Fix role claim mapping: OnTicketReceived + JsonWebTokenHandler (SOR.Admin)

ctx.TokenEndpointResponse?.AccessToken in OnTokenValidated is not reliably
populated; if null the silent catch left the principal with no role claims,
causing 403 on every request despite successful Keycloak auth.

Switch to OnTicketReceived which fires after SaveTokens — access token is
guaranteed present via ctx.Properties.GetTokenValue("access_token").
Use JsonWebTokenHandler.ReadJsonWebToken() instead of manual base64 decode
to eliminate silent parse failures. Extracts both realm_access.roles and
groups claims so either Keycloak assignment style works.

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:
dingo
2026-04-04 11:26:24 -04:00
co-authored by Claude Happy
parent 1b4a652e28
commit 20e5f5f212
2 changed files with 38 additions and 42 deletions
+1
View File
@@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" />
<!-- Design-time only: enables 'dotnet ef migrations add' targeting this project -->
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">