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
- Create a Spring Boot 4.0.0 application with
spring-boot-starter-oauth2-client
- Configure an OIDC provider (e.g., Azure AD / Microsoft Entra ID) with
openid scope in application.properties
- Enable
oauth2Login() in your SecurityFilterChain (default configuration, no custom token response client)
- Access a protected page (browser redirects to Azure AD)
- Authenticate successfully (Azure AD redirects back with an authorization code)
- Application exchanges the code for tokens using the default
RestClientAuthorizationCodeTokenResponseClient
- 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.
Describe the bug
RestClientAuthorizationCodeTokenResponseClient(new default in Spring Security 7.0.0) returns anOAuth2AccessTokenResponsewhereadditionalParametersis null instead of an empty Map. This causes aNullPointerExceptioninOidcAuthorizationCodeAuthenticationProvider.authenticate()at line 149, which callsaccessTokenResponse.getAdditionalParameters().containsKey(OidcParameterNames.ID_TOKEN)without a null check.The legacy
DefaultAuthorizationCodeTokenResponseClient(Spring Security 5.x/6.x) always returned a non-nulladditionalParametersmap containing theid_token, so this NPE only surfaces with the new RestClient-based implementation in 7.0.0.To Reproduce
spring-boot-starter-oauth2-clientopenidscope inapplication.propertiesoauth2Login()in yourSecurityFilterChain(default configuration, no custom token response client)RestClientAuthorizationCodeTokenResponseClientjava.lang.NullPointerException at org.springframework.security.oauth2.client.oidc.authentication.OidcAuthorizationCodeAuthenticationProvider.authenticate(OidcAuthorizationCodeAuthenticationProvider.java:149)Expected behavior
RestClientAuthorizationCodeTokenResponseClientshould return anOAuth2AccessTokenResponsewith a non-nulladditionalParametersmap (at minimum an empty map, but ideally containing theid_tokenfrom the token endpoint response). This would be consistent with the behavior of the previousDefaultAuthorizationCodeTokenResponseClientand would allowOidcAuthorizationCodeAuthenticationProviderto successfully extract the ID token and complete OIDC authentication.Alternatively,
OidcAuthorizationCodeAuthenticationProvider.authenticate()line ~149 should null-checkgetAdditionalParameters()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.