feat(EnvelopeSmsHandler): Methode VerifyTotp hinzugefügt, um Totp mit TotpVerificationWindow von TotpSmsParams zu verifizieren.

This commit is contained in:
Developer 02
2025-02-03 09:52:46 +01:00
parent 772d510705
commit bbd03615e1
4 changed files with 25 additions and 14 deletions

View File

@@ -1,4 +1,5 @@
using System.Globalization;
using OtpNet;
using System.Globalization;
namespace EnvelopeGenerator.Application.Configurations
{
@@ -13,6 +14,21 @@ namespace EnvelopeGenerator.Application.Configurations
public ExpirationHandler Expiration { get; init; } = new();
public VerificationWindow? TotpVerificationWindow { get; private init; } = VerificationWindow.RfcSpecifiedNetworkDelay;
private IEnumerable<int>? _tvwParams;
public IEnumerable<int>? TotpVerificationWindowParams
{
get => _tvwParams;
init
{
_tvwParams = value;
if(_tvwParams is not null)
TotpVerificationWindow = new(previous: _tvwParams.ElementAtOrDefault(0), future: _tvwParams.ElementAtOrDefault(0));
}
}
public class ExpirationHandler
{
public string CacheKeyFormat { get; init; } = "e{0}_r{1}_sms_code_expiration";

View File

@@ -12,4 +12,6 @@ public interface IEnvelopeSmsHandler
/// <param name="cToken"></param>
/// <returns></returns>
Task<(SmsResponse? SmsResponse, DateTime Expiration)> SendTotpAsync(EnvelopeReceiverSecretDto er_secret, CancellationToken cToken = default);
bool VerifyTotp(string totpCode, string secretKey);
}

View File

@@ -47,4 +47,7 @@ public class EnvelopeSmsHandler : IEnvelopeSmsHandler
return (await _sender.SendSmsAsync(er_secret.PhoneNumber!, msg), new_expiration);
}
}
public bool VerifyTotp(string totpCode, string secretKey) => _codeGenerator
.VerifyTotp(totpCode, secretKey, _totpSmsParams.TotpStep, _totpSmsParams.TotpVerificationWindow);
}