refactor: transfer logic
All logic related to token manipulation has been transferred to the AuthService. Also added TOTP 2FA and rethought the logic of logging into the application
This commit is contained in:
20
Security/Services/TotpService.cs
Normal file
20
Security/Services/TotpService.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using OtpNet;
|
||||
|
||||
namespace Mirea.Api.Security.Services;
|
||||
|
||||
public class TotpService
|
||||
{
|
||||
private readonly Totp _totp;
|
||||
|
||||
public TotpService(string secret)
|
||||
{
|
||||
var secretBytes = Base32Encoding.ToBytes(secret);
|
||||
_totp = new Totp(secretBytes);
|
||||
}
|
||||
|
||||
public string GenerateToken() =>
|
||||
_totp.ComputeTotp();
|
||||
|
||||
public bool VerifyToken(string token) =>
|
||||
_totp.VerifyTotp(token, out _, new VerificationWindow(2, 2));
|
||||
}
|
Reference in New Issue
Block a user