🐛 Still bug fixes in auth service

This commit is contained in:
2025-08-25 23:01:17 +08:00
parent 0221d7b294
commit c30946daf6
3 changed files with 16 additions and 10 deletions

View File

@@ -156,15 +156,16 @@ public class OidcProviderService(
var claims = new List<Claim> var claims = new List<Claim>
{ {
new Claim(JwtRegisteredClaimNames.Iss, _options.IssuerUri), new(JwtRegisteredClaimNames.Iss, _options.IssuerUri),
new Claim(JwtRegisteredClaimNames.Sub, session.AccountId.ToString()), new(JwtRegisteredClaimNames.Sub, session.AccountId.ToString()),
new Claim(JwtRegisteredClaimNames.Aud, client.Id.ToString()), new(JwtRegisteredClaimNames.Aud, client.Id.ToString()),
new Claim(JwtRegisteredClaimNames.Iat, now.ToUnixTimeSeconds().ToString(), ClaimValueTypes.Integer64), new(JwtRegisteredClaimNames.Iat, now.ToUnixTimeSeconds().ToString(), ClaimValueTypes.Integer64),
new Claim(JwtRegisteredClaimNames.Exp, new(JwtRegisteredClaimNames.Exp,
now.Plus(Duration.FromSeconds(_options.AccessTokenLifetime.TotalSeconds)).ToUnixTimeSeconds() now.Plus(Duration.FromSeconds(_options.AccessTokenLifetime.TotalSeconds)).ToUnixTimeSeconds()
.ToString(), ClaimValueTypes.Integer64), .ToString(), ClaimValueTypes.Integer64),
new Claim(JwtRegisteredClaimNames.AuthTime, session.CreatedAt.ToUnixTimeSeconds().ToString(), new(JwtRegisteredClaimNames.AuthTime, session.CreatedAt.ToUnixTimeSeconds().ToString(),
ClaimValueTypes.Integer64) ClaimValueTypes.Integer64),
new(JwtRegisteredClaimNames.Aud, client.Id)
}; };
// Add nonce if provided (required for implicit and hybrid flows) // Add nonce if provided (required for implicit and hybrid flows)
@@ -300,7 +301,7 @@ public class OidcProviderService(
new Claim(JwtRegisteredClaimNames.Jti, session.Id.ToString()), new Claim(JwtRegisteredClaimNames.Jti, session.Id.ToString()),
new Claim(JwtRegisteredClaimNames.Iat, now.ToUnixTimeSeconds().ToString(), new Claim(JwtRegisteredClaimNames.Iat, now.ToUnixTimeSeconds().ToString(),
ClaimValueTypes.Integer64), ClaimValueTypes.Integer64),
new Claim("client_id", client.Id) new Claim(JwtRegisteredClaimNames.Aud, client.Id)
]), ]),
Expires = expiresAt.ToDateTimeUtc(), Expires = expiresAt.ToDateTimeUtc(),
Issuer = _options.IssuerUri, Issuer = _options.IssuerUri,

View File

@@ -1,3 +1,4 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using DysonNetwork.Pass.Wallet; using DysonNetwork.Pass.Wallet;

View File

@@ -24,7 +24,7 @@ public class WebSocketController(WebSocketService ws, ILogger<WebSocketContext>
} }
var accountId = currentUser.Id!; var accountId = currentUser.Id!;
var deviceId = currentSession.Challenge.DeviceId!; var deviceId = currentSession.Challenge?.DeviceId ?? Guid.NewGuid().ToString();
if (string.IsNullOrEmpty(deviceId)) if (string.IsNullOrEmpty(deviceId))
{ {
@@ -67,7 +67,11 @@ public class WebSocketController(WebSocketService ws, ILogger<WebSocketContext>
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, logger.LogError(ex,
"WebSocket disconnected with user @{UserName}#{UserId} and device #{DeviceId} unexpectedly"); "WebSocket disconnected with user @{UserName}#{UserId} and device #{DeviceId} unexpectedly",
currentUser.Name,
currentUser.Id,
deviceId
);
} }
finally finally
{ {