update auth for refresh tokens and token invalidation

This commit is contained in:
voltsrage
2026-06-26 04:32:01 +08:00
parent 9777a335c5
commit abb33de5c1
20 changed files with 1183 additions and 12 deletions
@@ -0,0 +1,10 @@
public class AuthAuditEvent
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public AuthAuditEventType EventType { get; set; }
public DateTimeOffset OccurredAt { get; set; }
public string? MetadataJson { get; set; }
public User User { get; set; } = null!;
}
@@ -0,0 +1,13 @@
public class RefreshToken
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string TokenHash { get; set; } = null!;
public DateTimeOffset ExpiresAt { get; set; }
public DateTimeOffset? RevokedAt { get; set; }
public Guid? ReplacedByTokenId { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public User User { get; set; } = null!;
public RefreshToken? ReplacedByToken { get; set; }
}
@@ -0,0 +1,22 @@
public enum AuthAuditEventType
{
UserLogout,
TokenRefreshed
}
public static class AuthAuditEventTypeExtensions
{
public static string ToDbString(this AuthAuditEventType t) => t switch
{
AuthAuditEventType.UserLogout => "USER_LOGOUT",
AuthAuditEventType.TokenRefreshed => "TOKEN_REFRESHED",
_ => throw new ArgumentOutOfRangeException(nameof(t))
};
public static AuthAuditEventType FromDbString(string v) => v switch
{
"USER_LOGOUT" => AuthAuditEventType.UserLogout,
"TOKEN_REFRESHED" => AuthAuditEventType.TokenRefreshed,
_ => throw new ArgumentOutOfRangeException(nameof(v), $"Unknown auth audit event type: '{v}'")
};
}