Skip to content

NullPointerException in OidcAuthorizationCodeAuthenticationProvider when RestClientAuthorizationCodeTokenResponseClient returns null additionalParameters #18803

@roudi

Description

@roudi

Describe the bug
RestClientAuthorizationCodeTokenResponseClient (new default in Spring Security 7.0.0) returns an OAuth2AccessTokenResponse where additionalParameters is null instead of an empty Map. This causes a NullPointerException in OidcAuthorizationCodeAuthenticationProvider.authenticate() at line 149, which calls accessTokenResponse.getAdditionalParameters().containsKey(OidcParameterNames.ID_TOKEN) without a null check.

The legacy DefaultAuthorizationCodeTokenResponseClient (Spring Security 5.x/6.x) always returned a non-null additionalParameters map containing the id_token, so this NPE only surfaces with the new RestClient-based implementation in 7.0.0.

To Reproduce

  1. Create a Spring Boot 4.0.0 application with spring-boot-starter-oauth2-client
  2. Configure an OIDC provider (e.g., Azure AD / Microsoft Entra ID) with openid scope in application.properties
  3. Enable oauth2Login() in your SecurityFilterChain (default configuration, no custom token response client)
  4. Access a protected page (browser redirects to Azure AD)
  5. Authenticate successfully (Azure AD redirects back with an authorization code)
  6. Application exchanges the code for tokens using the default RestClientAuthorizationCodeTokenResponseClient
  7. NPE occurs: java.lang.NullPointerException at org.springframework.security.oauth2.client.oidc.authentication.OidcAuthorizationCodeAuthenticationProvider.authenticate(OidcAuthorizationCodeAuthenticationProvider.java:149)

Expected behavior
RestClientAuthorizationCodeTokenResponseClient should return an OAuth2AccessTokenResponse with a non-null additionalParameters map (at minimum an empty map, but ideally containing the id_token from the token endpoint response). This would be consistent with the behavior of the previous DefaultAuthorizationCodeTokenResponseClient and would allow OidcAuthorizationCodeAuthenticationProvider to successfully extract the ID token and complete OIDC authentication.

Alternatively, OidcAuthorizationCodeAuthenticationProvider.authenticate() line ~149 should null-check getAdditionalParameters() before calling .containsKey().

Sample

No sample repository provided. The issue is reproducible with any OIDC provider using the default oauth2Login() configuration on Spring Boot 4.0.0 / Spring Security 7.0.0.

Metadata

Metadata

Assignees

Labels

in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)status: invalidAn issue that we don't feel is valid

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions