-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoFactorConfiguration.cs
More file actions
175 lines (151 loc) · 6.69 KB
/
Copy pathTwoFactorConfiguration.cs
File metadata and controls
175 lines (151 loc) · 6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// This file is part of the DisCatSharp project.
//
// Copyright (c) 2021-2023 AITSYS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using Microsoft.Extensions.DependencyInjection;
using TwoFactorAuthNet;
namespace DisCatSharp.Extensions.TwoFactorCommands;
/// <summary>
/// Represents a configuration for <see cref="TwoFactorExtension" />.
/// </summary>
public sealed class TwoFactorConfiguration
{
/// <summary>
/// Creates a new instance of <see cref="TwoFactorConfiguration" />.
/// </summary>
[ActivatorUtilitiesConstructor]
public TwoFactorConfiguration()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="TwoFactorConfiguration" /> class.
/// </summary>
/// <param name="provider">The service provider.</param>
[ActivatorUtilitiesConstructor]
public TwoFactorConfiguration(IServiceProvider provider)
{
this.ServiceProvider = provider;
}
/// <summary>
/// Creates a new instance of <see cref="TwoFactorConfiguration" />, copying the properties of another configuration.
/// </summary>
/// <param name="other">Configuration the properties of which are to be copied.</param>
public TwoFactorConfiguration(TwoFactorConfiguration other)
{
this.Digits = other.Digits;
this.Period = other.Period;
this.Algorithm = other.Algorithm;
this.Issuer = other.Issuer;
this.ResponseConfiguration = other.ResponseConfiguration;
}
/// <summary>
/// <para>Sets the service provider for this TwoFactor instance.</para>
/// <para>
/// Objects in this provider are used when instantiating command modules. This allows passing data around without
/// resorting to static members.
/// </para>
/// <para>Defaults to an empty service provider.</para>
/// </summary>
public IServiceProvider ServiceProvider { internal get; set; } = new ServiceCollection().BuildServiceProvider(true);
/// <summary>
/// Sets the length of digits for the 2fa code. Defaults to <c>6</c>.
/// </summary>
public int Digits { internal get; set; } = 6;
/// <summary>
/// Sets the period in seconds how long a code is valid. Defaults to <c>30</c> seconds..
/// </summary>
public int Period { internal get; set; } = 30;
/// <summary>
/// Sets the algorithm. Defaults to <see cref="TwoFactorAuthNet.Algorithm.SHA1" />.
/// </summary>
public Algorithm Algorithm { internal get; set; } = Algorithm.SHA1;
/// <summary>
/// <para>Sets the issuer.</para>
/// <para>Defaults to <c>aitsys.dev</c> to show the DisCatSharp logo.</para>
/// </summary>
public string Issuer { internal get; set; } = "aitsys.dev";
/// <summary>
/// Sets the database path. Defaults to <c>./twofactor.sqlite</c>.
/// </summary>
public string DatabasePath { internal get; set; } = "./twofactor.sqlite";
/// <summary>
/// Sets how long user have to enter the 2fa code. Defaults to <c>30</c> seconds.
/// </summary>
public int TwoFactorTimeout { internal get; set; } = 30;
/// <summary>
/// Sets overrides for default messages facing the user.
/// </summary>
public TwoFactorResponseConfiguration ResponseConfiguration { internal get; set; } = new();
}
/// <summary>
/// Represents a message configuration for <see cref="TwoFactorExtension" />.
/// </summary>
public sealed class TwoFactorResponseConfiguration
{
/// <summary>
/// Creates a new instance of <see cref="TwoFactorResponseConfiguration" />.
/// </summary>
[ActivatorUtilitiesConstructor]
public TwoFactorResponseConfiguration()
{ }
/// <summary>
/// <para>
/// Whether to show a response after entering a two factor code. If set to false, you'll need to respond to the
/// modal interaction yourself.
/// </para>
/// <para>Defaults to: true</para>
/// </summary>
public bool ShowResponse { internal get; set; } = true;
/// <summary>
/// <para>Sets the message when an correct two factor auth code was entered.</para>
/// <para>Defaults to: Code valid!</para>
/// </summary>
public string AuthenticationSuccessMessage { internal get; set; } = "Code valid!";
/// <summary>
/// <para>Sets the message when an incorrect two factor auth code was entered.</para>
/// <para>Defaults to: Code invalid..</para>
/// </summary>
public string AuthenticationFailureMessage { internal get; set; } = "Code invalid..";
/// <summary>
/// <para>Sets the message when an user successfully enrolled into two factor auth.</para>
/// <para>Defaults to: You successfully enrolled in two factor.</para>
/// </summary>
public string AuthenticationEnrolledMessage { internal get; set; } = "You successfully enrolled in two factor.";
/// <summary>
/// <para>Sets the message when an user successfully unenrolled from two factor auth.</para>
/// <para>Defaults to: You successfully unenrolled from two factor.</para>
/// </summary>
public string AuthenticationUnenrolledMessage { internal get; set; } = "You successfully unenrolled from two factor.";
/// <summary>
/// <para>Sets the message when an user is not yet enrolled into two factor auth.</para>
/// <para>Defaults to: You are not enrolled in two factor.</para>
/// </summary>
public string AuthenticationNotEnrolledMessage { internal get; set; } = "You are not enrolled in two factor.";
/// <summary>
/// <para>Sets the modal title for two factor auth requests.</para>
/// <para>Defaults to: Enter 2FA Code</para>
/// </summary>
public string AuthenticationModalRequestTitle { internal get; set; } = "Enter 2FA Code";
/// <summary>
/// <para>Sets the account prefix used within the authenticator upon registration.</para>
/// <para>Defaults to: DisCatSharp Auth</para>
/// </summary>
public string AuthenticatorAccountPrefix { internal get; set; } = "DisCatSharp Auth";
}