Add Keycloak authentication via Authorization Code + PKCE
- auth.proto: add ExchangeKeycloakToken RPC + request/response messages - KeycloakOptions: binds Keycloak:Authority + Keycloak:ClientId from config - KeycloakTokenValidator: validates Keycloak JWTs via OIDC discovery/JWKS; extracts sub, email, preferred_username, realm_access.roles - AuthGrpcHandler.ExchangeKeycloakToken: - validates JWT and requires "player" realm role - lazy-migrates existing accounts by email on first Keycloak login - creates new passwordless accounts from Keycloak claims - syncs preferred_username → DisplayName on every login - single-session policy: revokes prior sessions before issuing SOR token - AuthGrpcHandler.Register: assign "player" role to all new registrations - ServiceRegistration: wire KeycloakOptions + KeycloakTokenValidator as singleton - Admin SeedAsync: seed player, moderator, card_builder roles alongside Admin/SuperAdmin - IGatewayAuthValidator / GatewayAuthValidator: add ExchangeKeycloakTokenAsync - ConnectionLoop: handle auth.keycloak message type → auth.keycloak.ack - appsettings.json: add Keycloak section (Authority + ClientId, overridable via env) Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
namespace SOR.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Bound from the "Keycloak" section of appsettings.
|
||||
///
|
||||
/// "Keycloak": {
|
||||
/// "Authority": "https://auth.aeternalisgames.com/realms/aeternalis",
|
||||
/// "ClientId": "sor-game"
|
||||
/// }
|
||||
///
|
||||
/// Authority is the Keycloak realm URL — used as the JWT issuer and as the base
|
||||
/// for OIDC discovery (Authority/.well-known/openid-configuration).
|
||||
/// ClientId must match the "aud" claim in the access token.
|
||||
/// </summary>
|
||||
public sealed class KeycloakOptions
|
||||
{
|
||||
public const string Section = "Keycloak";
|
||||
|
||||
/// <summary>Keycloak realm URL, e.g. https://auth.aeternalisgames.com/realms/aeternalis</summary>
|
||||
public string Authority { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Keycloak client ID configured for the game, e.g. sor-game</summary>
|
||||
public string ClientId { get; set; } = string.Empty;
|
||||
}
|
||||
Reference in New Issue
Block a user