Token fix?
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user