Skip to content

Fix WebAuthn OIDC id_token missing sid and auth_time with SpringSessionBackedSessionRegistry#19215

Open
jyx-07 wants to merge 1 commit into
spring-projects:mainfrom
jyx-07:fix/gh-19202-webauthn-oidc-sid-auth-time
Open

Fix WebAuthn OIDC id_token missing sid and auth_time with SpringSessionBackedSessionRegistry#19215
jyx-07 wants to merge 1 commit into
spring-projects:mainfrom
jyx-07:fix/gh-19202-webauthn-oidc-sid-auth-time

Conversation

@jyx-07
Copy link
Copy Markdown

@jyx-07 jyx-07 commented May 25, 2026

Problem

After WebAuthn login, the OIDC id_token is missing both sid and auth_time claims when SpringSessionBackedSessionRegistry is used. Username/password login works correctly.

Fixes #19202

Root Cause

OAuth2AuthorizationCodeAuthenticationProvider.getSessionInformation() passes principal.getPrincipal() (a PublicKeyCredentialUserEntity) to SessionRegistry.getAllSessions().

SpringSessionBackedSessionRegistry extracts the principal name internally by wrapping it in an AbstractAuthenticationToken and calling getName(). Since PublicKeyCredentialUserEntity did not implement UserDetails, AuthenticatedPrincipal, or java.security.Principal, getName() fell through to toString(), producing a garbage string. Spring Session then found no sessions under that key, so SessionInformation was never placed in the token context, and JwtGenerator skipped both claims.

SessionRegistryImpl was unaffected because it uses object equality (equals()/hashCode()) for lookup.

Fix

Make PublicKeyCredentialUserEntity extend AuthenticatedPrincipal. The interface already declares String getName() returning the username, so no method changes are needed. This causes AbstractAuthenticationToken.getName() to hit the instanceof AuthenticatedPrincipal branch and return the correct username.

…ngSessionBackedSessionRegistry

PublicKeyCredentialUserEntity did not implement AuthenticatedPrincipal, so
SpringSessionBackedSessionRegistry fell through to toString() when extracting
the principal name, causing session lookup to fail and both sid and auth_time
claims to be omitted from the OIDC id_token.

Fixes spring-projectsgh-19202

Signed-off-by: jyx-07 <s25069@gsm.hs.kr>
@jyx-07 jyx-07 force-pushed the fix/gh-19202-webauthn-oidc-sid-auth-time branch from 38b1cb9 to f4ce801 Compare May 25, 2026 12:45
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing sid- and auth_time-claims in ID-token in case of WebAuthn

2 participants