Invalidate JWTs on profile changes

This commit is contained in:
Holden
2026-06-28 12:46:12 -05:00
parent fefa01cf3f
commit e194bbf9c4
15 changed files with 395 additions and 47 deletions

View File

@@ -16,4 +16,15 @@ public static class ClaimsPrincipalExtensions
return profileId;
}
public static Guid GetTokenVersion(this ClaimsPrincipal user)
{
var value = user.FindFirst("token_version")?.Value;
if (!Guid.TryParse(value, out var tokenVersion))
throw new UnauthorizedAccessException(
"Token version claim is missing or invalid.");
return tokenVersion;
}
}

View File

@@ -2,11 +2,12 @@ namespace RecNet.Application.Common.Tokens;
public sealed record TokenVerifyResult(
bool Succeeded,
Guid? ProfileId)
Guid? ProfileId,
Guid? TokenVersion)
{
public static TokenVerifyResult Success(Guid profileId)
=> new(true, profileId);
public static TokenVerifyResult Success(Guid profileId, Guid tokenVersion)
=> new(true, profileId, tokenVersion);
public static TokenVerifyResult Failure()
=> new(false, null);
=> new(false, null, null);
}