Token fix?

This commit is contained in:
dingo
2025-12-04 15:37:22 -05:00
parent ea3cf510e5
commit 4decec8ff2
2 changed files with 30 additions and 11 deletions
+6 -6
View File
@@ -45,10 +45,10 @@ public sealed class AdminAuthService : IAdminAuthService
using var scope = _scopeFactory.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
// Hash the token to match against stored hash
var tokenHash = HashTokenToString(token);
// Hash the token to match against stored hash (base64 format)
var tokenHash = HashTokenToBase64(token);
_log.LogDebug("Validating token hash: {Hash}", tokenHash);
_log.LogDebug("Validating token, computed hash: {Hash}", tokenHash);
// Find valid session with this token
var session = await db.Sessions
@@ -60,7 +60,7 @@ public sealed class AdminAuthService : IAdminAuthService
if (session == null)
{
_log.LogDebug("No session found for hash {Hash}", tokenHash);
_log.LogWarning("No session found for token hash: {Hash}", tokenHash);
return AdminAuthResult.Fail("Invalid or expired token");
}
@@ -79,10 +79,10 @@ public sealed class AdminAuthService : IAdminAuthService
return AdminAuthResult.Success(account);
}
private static string HashTokenToString(string token)
private static string HashTokenToBase64(string token)
{
using var sha = System.Security.Cryptography.SHA256.Create();
var hashBytes = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(token));
return Convert.ToHexString(hashBytes).ToLowerInvariant(); // Hex is safer than base64
return Convert.ToBase64String(hashBytes);
}
}