diff --git a/EnvelopeGenerator.Application/Configurations/CodeGeneratorParams.cs b/EnvelopeGenerator.Application/Configurations/AuthenticatorParams.cs similarity index 95% rename from EnvelopeGenerator.Application/Configurations/CodeGeneratorParams.cs rename to EnvelopeGenerator.Application/Configurations/AuthenticatorParams.cs index 2ba65399..bfec74f1 100644 --- a/EnvelopeGenerator.Application/Configurations/CodeGeneratorParams.cs +++ b/EnvelopeGenerator.Application/Configurations/AuthenticatorParams.cs @@ -1,6 +1,6 @@ namespace EnvelopeGenerator.Application.Configurations { - public class CodeGeneratorParams + public class AuthenticatorParams { public string CharPool { get; init; } = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789012345678901234567890123456789"; diff --git a/EnvelopeGenerator.Application/Contracts/ICodeGenerator.cs b/EnvelopeGenerator.Application/Contracts/IAuthenticator.cs similarity index 94% rename from EnvelopeGenerator.Application/Contracts/ICodeGenerator.cs rename to EnvelopeGenerator.Application/Contracts/IAuthenticator.cs index d4e93c6b..1e3cf1a0 100644 --- a/EnvelopeGenerator.Application/Contracts/ICodeGenerator.cs +++ b/EnvelopeGenerator.Application/Contracts/IAuthenticator.cs @@ -2,7 +2,7 @@ namespace EnvelopeGenerator.Application.Contracts { - public interface ICodeGenerator + public interface IAuthenticator { string GenerateCode(int length); diff --git a/EnvelopeGenerator.Application/Extensions/DIExtensions.cs b/EnvelopeGenerator.Application/Extensions/DIExtensions.cs index 59c56724..6ebadb61 100644 --- a/EnvelopeGenerator.Application/Extensions/DIExtensions.cs +++ b/EnvelopeGenerator.Application/Extensions/DIExtensions.cs @@ -55,13 +55,13 @@ namespace EnvelopeGenerator.Application.Extensions services.ConfigureByTypeName(config); services.ConfigureByTypeName(config); - services.ConfigureByTypeName(config); + services.ConfigureByTypeName(config); services.ConfigureByTypeName(config); services.AddHttpClientService(config.GetSection(nameof(GtxMessagingParams))); services.TryAddSingleton(); services.TryAddSingleton(); - services.TryAddSingleton(); + services.TryAddSingleton(); services.TryAddSingleton(); return services; diff --git a/EnvelopeGenerator.Application/Services/CodeGenerator.cs b/EnvelopeGenerator.Application/Services/Authenticator.cs similarity index 88% rename from EnvelopeGenerator.Application/Services/CodeGenerator.cs rename to EnvelopeGenerator.Application/Services/Authenticator.cs index ca84bfc9..af410d9a 100644 --- a/EnvelopeGenerator.Application/Services/CodeGenerator.cs +++ b/EnvelopeGenerator.Application/Services/Authenticator.cs @@ -7,17 +7,17 @@ using System.Text; namespace EnvelopeGenerator.Application.Services { - public class CodeGenerator : ICodeGenerator + public class Authenticator : IAuthenticator { - public static Lazy LazyStatic => new(() => new CodeGenerator(Options.Create(new()), new QRCodeGenerator())); + public static Lazy LazyStatic => new(() => new Authenticator(Options.Create(new()), new QRCodeGenerator())); - public static CodeGenerator Static => LazyStatic.Value; + public static Authenticator Static => LazyStatic.Value; - private readonly CodeGeneratorParams _params; + private readonly AuthenticatorParams _params; private readonly QRCodeGenerator _qrCodeGenerator; - public CodeGenerator(IOptions options, QRCodeGenerator qrCodeGenerator) + public Authenticator(IOptions options, QRCodeGenerator qrCodeGenerator) { _params = options.Value; _qrCodeGenerator = qrCodeGenerator; diff --git a/EnvelopeGenerator.Application/Services/EnvelopeMailService.cs b/EnvelopeGenerator.Application/Services/EnvelopeMailService.cs index 235383d6..afd313db 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeMailService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeMailService.cs @@ -24,16 +24,16 @@ namespace EnvelopeGenerator.Application.Services private readonly DispatcherParams _dConfig; private readonly IConfigService _configService; private readonly Dictionary _placeholders; - private readonly ICodeGenerator _codeGenerator; + private readonly IAuthenticator _authenticator; - public EnvelopeMailService(IEmailOutRepository repository, IMapper mapper, IEmailTemplateService tempService, IEnvelopeReceiverService envelopeReceiverService, IOptions dispatcherConfigOptions, IConfigService configService, IOptions mailConfig, ICodeGenerator codeGenerator) : base(repository, mapper) + public EnvelopeMailService(IEmailOutRepository repository, IMapper mapper, IEmailTemplateService tempService, IEnvelopeReceiverService envelopeReceiverService, IOptions dispatcherConfigOptions, IConfigService configService, IOptions mailConfig, IAuthenticator authenticator) : base(repository, mapper) { _tempService = tempService; _envRcvService = envelopeReceiverService; _dConfig = dispatcherConfigOptions.Value; _configService = configService; _placeholders = mailConfig.Value.Placeholders; - _codeGenerator = codeGenerator; + _authenticator = authenticator; } private async Task> CreatePlaceholders(string? accessCode = null, EnvelopeReceiverDto? envelopeReceiverDto = null) @@ -167,7 +167,7 @@ namespace EnvelopeGenerator.Application.Services if (dto.Receiver.TotpExpiration is null) throw new ArgumentNullException(nameof(dto), $"TFA Qr Code cannot sent. Receiver.TotpExpiration is null. Envelope receiver dto is {JsonConvert.SerializeObject(dto)}"); - var totp_qr_64 = _codeGenerator.GenerateTotpQrCode(userEmail: dto.Receiver.EmailAddress, secretKey: dto.Receiver.TotpSecretkey).ToBase64String(); + var totp_qr_64 = _authenticator.GenerateTotpQrCode(userEmail: dto.Receiver.EmailAddress, secretKey: dto.Receiver.TotpSecretkey).ToBase64String(); return SendAsync(dto, EmailTemplateType.TotpSecret, new() { {"[TFA_QR_CODE]", totp_qr_64 }, diff --git a/EnvelopeGenerator.Application/Services/EnvelopeSmsHandler.cs b/EnvelopeGenerator.Application/Services/EnvelopeSmsHandler.cs index 0a72c7d4..dfea09e6 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeSmsHandler.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeSmsHandler.cs @@ -16,14 +16,14 @@ public class EnvelopeSmsHandler : IEnvelopeSmsHandler private readonly IDistributedCache _dCache; - private readonly ICodeGenerator _codeGenerator; + private readonly IAuthenticator _authenticator; - public EnvelopeSmsHandler(ISmsSender sender, IOptions totpSmsParamsOptions, IDistributedCache distributedCache, ICodeGenerator codeGenerator) + public EnvelopeSmsHandler(ISmsSender sender, IOptions totpSmsParamsOptions, IDistributedCache distributedCache, IAuthenticator authenticator) { _sender = sender; _totpSmsParams = totpSmsParamsOptions.Value; _dCache = distributedCache; - _codeGenerator = codeGenerator; + _authenticator = authenticator; } /// @@ -42,12 +42,12 @@ public class EnvelopeSmsHandler : IEnvelopeSmsHandler else { var new_expiration = DateTime.Now.AddSeconds(_totpSmsParams.TotpStep); - var totp = _codeGenerator.GenerateTotp(er_secret.Receiver!.TotpSecretkey!, _totpSmsParams.TotpStep); + var totp = _authenticator.GenerateTotp(er_secret.Receiver!.TotpSecretkey!, _totpSmsParams.TotpStep); var msg = string.Format(_totpSmsParams.Format, totp, new_expiration.ToString(_totpSmsParams.Expiration.Format, _totpSmsParams.Expiration.CultureInfo)); return (await _sender.SendSmsAsync(er_secret.PhoneNumber!, msg), new_expiration); } } - public bool VerifyTotp(string totpCode, string secretKey) => _codeGenerator + public bool VerifyTotp(string totpCode, string secretKey) => _authenticator .VerifyTotp(totpCode, secretKey, _totpSmsParams.TotpStep, _totpSmsParams.TotpVerificationWindow); } \ No newline at end of file diff --git a/EnvelopeGenerator.Web/Controllers/HomeController.cs b/EnvelopeGenerator.Web/Controllers/HomeController.cs index 3a75b946..fc4c52b8 100644 --- a/EnvelopeGenerator.Web/Controllers/HomeController.cs +++ b/EnvelopeGenerator.Web/Controllers/HomeController.cs @@ -35,11 +35,11 @@ namespace EnvelopeGenerator.Web.Controllers private readonly Cultures _cultures; private readonly IEnvelopeMailService _mailService; private readonly IEnvelopeReceiverReadOnlyService _readOnlyService; - private readonly ICodeGenerator _codeGenerator; + private readonly IAuthenticator _authenticator; private readonly IReceiverService _rcvService; private readonly IEnvelopeSmsHandler _envSmsHandler; - public HomeController(EnvelopeOldService envelopeOldService, ILogger logger, IEnvelopeReceiverService envelopeReceiverService, IEnvelopeHistoryService historyService, IStringLocalizer localizer, IConfiguration configuration, HtmlSanitizer sanitizer, Cultures cultures, IEnvelopeMailService envelopeMailService, IEnvelopeReceiverReadOnlyService readOnlyService, ICodeGenerator codeGenerator, IReceiverService receiverService, IEnvelopeSmsHandler envelopeSmsService) + public HomeController(EnvelopeOldService envelopeOldService, ILogger logger, IEnvelopeReceiverService envelopeReceiverService, IEnvelopeHistoryService historyService, IStringLocalizer localizer, IConfiguration configuration, HtmlSanitizer sanitizer, Cultures cultures, IEnvelopeMailService envelopeMailService, IEnvelopeReceiverReadOnlyService readOnlyService, IAuthenticator authenticator, IReceiverService receiverService, IEnvelopeSmsHandler envelopeSmsService) { this.envelopeOldService = envelopeOldService; _envRcvService = envelopeReceiverService; @@ -51,7 +51,7 @@ namespace EnvelopeGenerator.Web.Controllers _mailService = envelopeMailService; _logger = logger; _readOnlyService = readOnlyService; - _codeGenerator = codeGenerator; + _authenticator = authenticator; _rcvService = receiverService; _envSmsHandler = envelopeSmsService; } @@ -204,7 +204,7 @@ namespace EnvelopeGenerator.Web.Controllers var rcv = er_secret.Receiver; if (rcv.IsTotpSecretInvalid()) { - rcv.TotpSecretkey = _codeGenerator.GenerateTotpSecretKey(); + rcv.TotpSecretkey = _authenticator.GenerateTotpSecretKey(); rcv.TotpExpiration = DateTime.Now.AddMonths(1); await _rcvService.UpdateAsync(rcv); await _mailService.SendTFAQrCodeAsync(er_secret);