OtpNet ile RFC 6238 TOTP — secret üretimi, otpauth:// QR URI ve drift toleranslı doğrulama.
Authenticator servisi src/DiyanetCleanArchitecture.Infrastructure.Services.Authenticator projesindedir. Google Authenticator / Microsoft Authenticator gibi uygulamalarla uyumlu TOTP (Time-based One-Time Password, RFC 6238) üretir ve doğrular. Altında OtpNet kütüphanesi çalışır.
GenerateQrCodeUri, authenticator uygulamalarının okuduğu standart otpauth://totp/... URI’sini üretir. Issuer ve account adı URL-encode edilir; algoritma, basamak ve periyot config’ten gelir:
VerifyCode, kodu Base32 secret ile doğrular. Saat kayması için AllowedDriftSteps kadar (default ±1 time step) pencere uygulanır. Eşleşen timeStepout parametresiyle döner (replay/önceki kullanım kontrolü için):
var totp = new Totp(secretBytes, step: _options.TimeStepSeconds, totpSize: _options.Digits, mode: _hashMode);var window = new VerificationWindow( previous: _options.AllowedDriftSteps, future: _options.AllowedDriftSteps);return totp.VerifyTotp(code, out timeStep, window);
Servis fail-closed’dur: geçersiz Base32, sayısal olmayan kod ya da beklenmedik herhangi bir hata false döner — asla “doğru” kabul etmez.
User aggregate metodları: ConfigureTotp (secret atar, henüz aktif değil), EnableTotp (ilk doğru kod ile etkinleştirir), VerifyTotp, DisableTotp.
TotpSecret DataProtection ile şifreli saklanır.ITotpSecretProtector (impl: TotpSecretProtector) ASP.NET Core IDataProtectionProvider’ı "TotpSecret" purpose’u ile kullanır. DB’ye düz secret asla yazılmaz; QR/manuel giriş için düz secret yalnızca configure anında, response’da bir kez döner.