feat/Update_Controllers_to_Allow_for_Premium_Membership

This commit is contained in:
cesnimda
2026-08-03 09:17:28 +02:00
parent de937d25dc
commit c3f4a57195
187 changed files with 26062 additions and 991 deletions
@@ -29,8 +29,9 @@ public sealed class TwoFactorController : ControllerBase
private readonly ITwoFactorPendingTokenService _pending;
private readonly IDataProtector _protector;
private readonly IConfiguration _cfg;
private readonly ExternalOrigin _externalOrigin;
public TwoFactorController(UserManager<ApplicationUser> users, ITokenService tokens, JobTrackerContext db, ITwoFactorPendingTokenService pending, IDataProtectionProvider protectionProvider, IConfiguration cfg)
public TwoFactorController(UserManager<ApplicationUser> users, ITokenService tokens, JobTrackerContext db, ITwoFactorPendingTokenService pending, IDataProtectionProvider protectionProvider, IConfiguration cfg, ExternalOrigin? externalOrigin = null)
{
_users = users;
_tokens = tokens;
@@ -38,6 +39,7 @@ public sealed class TwoFactorController : ControllerBase
_pending = pending;
_protector = protectionProvider.CreateProtector("totp-secret-v1");
_cfg = cfg;
_externalOrigin = externalOrigin ?? ExternalOrigin.FromConfiguration(cfg);
}
public sealed record PasswordConfirmRequest(string CurrentPassword);
@@ -198,17 +200,23 @@ public sealed class TwoFactorController : ControllerBase
{
return Unauthorized();
}
if (session.SecurityStamp is not null
&& !string.Equals(session.SecurityStamp, user.SecurityStamp, StringComparison.Ordinal))
{
_pending.Resolve(pendingToken, consume: true);
return Unauthorized();
}
var base32Secret = _protector.Unprotect(user.TotpSecretEncrypted);
var verified = VerifyCode(base32Secret, code) || await TryConsumeRecoveryCodeAsync(user.Id, code, cancellationToken);
if (!verified) return Unauthorized();
_pending.Resolve(pendingToken, consume: true);
await AppSessionIssuer.IssueAsync(Request, Response, _tokens, _db, _cfg, user, session.RememberMe, cancellationToken);
await AppSessionIssuer.IssueAsync(Request, Response, _tokens, _db, _cfg, user, session.RememberMe, _externalOrigin.UsesHttps, cancellationToken);
if (request.TrustDevice)
{
await TrustedDeviceService.IssueAsync(_db, Request, Response, user.Id, cancellationToken);
await TrustedDeviceService.IssueAsync(_db, Request, Response, user.Id, _externalOrigin.UsesHttps, cancellationToken);
}
return Ok(new AuthController.AuthSessionResult(true, "local"));
@@ -250,7 +258,7 @@ public sealed class TwoFactorController : ControllerBase
if (isCurrentDevice)
{
TrustedDeviceService.ClearCookie(Request, Response);
TrustedDeviceService.ClearCookie(Response, _externalOrigin.UsesHttps);
}
return NoContent();
@@ -270,7 +278,7 @@ public sealed class TwoFactorController : ControllerBase
await _db.SaveChangesAsync(cancellationToken);
}
TrustedDeviceService.ClearCookie(Request, Response);
TrustedDeviceService.ClearCookie(Response, _externalOrigin.UsesHttps);
return NoContent();
}