Describe the bug
Scope mapping handling changed with #12112.
2915a70#diff-73bd44f873d78e3d71e6a0fa18644a304d562a4a9fd2e303e913f6ed20a0ad16R78-R83

OidcAuthorizationCodeAuthenticationProvider.authenticate() calls OidcAuthorizationCodeAuthenticationProvider.getResponse())
DefaultAuthorizationCodeTokenResponseClient.getTokenResponse does NOT add the scopes anymore. If no scopes are returned by default by the IdP, the scopes list is empty.
- The comment
If AccessTokenResponse.scope is empty, then we assume all requested scopes were granted. seems to say something completely different.
- Back in
OidcAuthorizationCodeAuthenticationProvider.authenticate() the user info has to be loaded: this.userService.loadUser().
OidcUserService.loadUser calls this.shouldRetrieveUserInfo(userRequest) which returns false now, because the scopes (userRequest.getAccessToken().getScopes()) is empty.
- Because of this the userInfo is not loaded (it is
null) and can't be used for example in the userAuthoritiesMapper.
To Reproduce
Our scopes are configured like this:
spring.security.oauth2.client.registration.default.scope=openid,profile,entitlements
Use the userAuthoritiesMapper with a token-uri endpoint that doesn't return a list of scopes.
http.oauth2Login()
.userInfoEndpoint().userAuthoritiesMapper(this.userAuthoritiesMapper());
In the authorities mapper try to use the oidcUserAuthority.getUserInfo() (which is now null).
Expected behavior
oidcUserAuthority.getUserInfo() should not be null.
Sample
No sample yet.
Ping @sjohnr
Describe the bug
Scope mapping handling changed with #12112.
2915a70#diff-73bd44f873d78e3d71e6a0fa18644a304d562a4a9fd2e303e913f6ed20a0ad16R78-R83
OidcAuthorizationCodeAuthenticationProvider.authenticate()callsOidcAuthorizationCodeAuthenticationProvider.getResponse())DefaultAuthorizationCodeTokenResponseClient.getTokenResponsedoes NOT add the scopes anymore. If no scopes are returned by default by the IdP, the scopes list is empty.If AccessTokenResponse.scope is empty, then we assume all requested scopes were granted.seems to say something completely different.OidcAuthorizationCodeAuthenticationProvider.authenticate()the user info has to be loaded:this.userService.loadUser().OidcUserService.loadUsercallsthis.shouldRetrieveUserInfo(userRequest)which returnsfalsenow, because the scopes (userRequest.getAccessToken().getScopes()) is empty.null) and can't be used for example in theuserAuthoritiesMapper.To Reproduce
Our scopes are configured like this:
Use the
userAuthoritiesMapperwith a token-uri endpoint that doesn't return a list of scopes.In the authorities mapper try to use the
oidcUserAuthority.getUserInfo()(which is now null).Expected behavior
oidcUserAuthority.getUserInfo()should not benull.Sample
No sample yet.
Ping @sjohnr