diff --git a/Client/origin-client/autoloads/Network.gd b/Client/origin-client/autoloads/Network.gd index d77086a..e5386ca 100644 --- a/Client/origin-client/autoloads/Network.gd +++ b/Client/origin-client/autoloads/Network.gd @@ -95,6 +95,10 @@ func _process(delta: float) -> void: return WebSocketPeer.STATE_CLOSING: + # Drain any data packets that arrived before the close frame so they + # are resolved via their pending callbacks rather than as DISCONNECTED. + if _state == _State.CONNECTED: + _poll_packets() return # Wait for STATE_CLOSED on the next poll. # Only run packet/keepalive while fully connected. @@ -186,12 +190,15 @@ func _on_ws_closed() -> void: var error_code: String var error_msg: String match reason: - "auth_failed": + "auth_failed", "invalid_token", "role_required", "invalid_payload": error_code = "AUTH_FAILED" - error_msg = "Session expired or revoked." + error_msg = "Authentication failed." "auth_required": error_code = "AUTH_REQUIRED" error_msg = "Authentication required." + "auth_service_unavailable", "account_creation_failed": + error_code = "AUTH_SERVICE_UNAVAILABLE" + error_msg = "Server unavailable." _: error_code = "DISCONNECTED" error_msg = "Connection lost." diff --git a/Server/src/SOR.Auth/KeycloakTokenValidator.cs b/Server/src/SOR.Auth/KeycloakTokenValidator.cs index 2c183a9..16ef666 100644 --- a/Server/src/SOR.Auth/KeycloakTokenValidator.cs +++ b/Server/src/SOR.Auth/KeycloakTokenValidator.cs @@ -37,9 +37,12 @@ public sealed class KeycloakTokenValidator _baseParams = new TokenValidationParameters { ValidIssuer = opts.Authority, - ValidAudience = opts.ClientId, ValidateIssuer = true, - ValidateAudience = true, + // Audience: Keycloak does not add the client ID to the `aud` claim by default + // (it uses "account"). We validate the issuer + signature + realm roles instead, + // which is sufficient for a single-realm deployment. Add an Audience protocol + // mapper in Keycloak if you need strict audience enforcement. + ValidateAudience = false, ValidateLifetime = true, ValidateIssuerSigningKey = true, // Clock skew: allow 30 s to account for minor time drift between servers. @@ -68,7 +71,7 @@ public sealed class KeycloakTokenValidator if (!result.IsValid) { - _logger.LogDebug("Keycloak JWT validation failed: {Reason}", result.Exception?.Message); + _logger.LogInformation("Keycloak JWT validation failed: {Reason}", result.Exception?.Message); return KeycloakClaimsResult.Invalid; }