Get userInfo, if scopes in token is empty #12513
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In a WebFlux app, with OIDC authentication, the userInfo request is handled here:
spring-security/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/userinfo/OidcReactiveOAuth2UserService.java
Lines 125 to 128 in 556891b
Here, we call the
OidcUserRequestUtils.shouldRetrieveUserInfo
static function, to determine if we should douserInfo
. In this function, we check if the scopes in the token, and the configured scopes match:spring-security/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/userinfo/OidcUserRequestUtils.java
Lines 60 to 65 in 556891b
Now consider this check for a non-Webflux (non-reactive) OIDC authentication:
spring-security/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/userinfo/OidcUserService.java
Lines 172 to 184 in 556891b
We can see two major differences:
The non-Webflux flow, when it encounters missing scope field, or empty scope field, it will call the
userInfo
endpoint. Whereas the Webflux flow will not.The non-Webflux flow, also checks
this.accessibleScopes.isEmpty()
. Overriding thisaccessibleScopes
has been recommended, to handle cases like missing scope in token. But this affordance is missing in the Webflux flow.So, when using Webflux, I don't see a way out. Can we add these (at least the first) one, to the Webflux's flow as well? That's what this PR does. If the scopes are missing/empty in the token, do call the
userInfo
endpoint.Thank you for your time.