Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider a lenient scope validation strategy in OAuth2ClientCredentialsAuthenticationProvider #884

Closed
yonyes opened this issue Sep 6, 2022 · 7 comments
Assignees
Labels
status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@yonyes
Copy link
Contributor

yonyes commented Sep 6, 2022

Expected Behavior

When a token request includes scopes that part of them aren't permitted, return the new token with only the permitted scopes

Current Behavior

When a token request includes scopes that part of them aren't permitted, it raises an internal exception, and the request answer is 400:
{ "error": "invalid_scope" }

Context

It's not a rare scenario that permissions of clients are changed and the clients themselves are not always updated immediately (or at all). It makes sense to generate the token with the scopes it allowed instead of failing the request.

The relevant code is in the OAuth2ClientCredentialsAuthenticationProvider.java

for (String requestedScope : clientCredentialsAuthentication.getScopes()) { if (!registeredClient.getScopes().contains(requestedScope)) { throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_SCOPE); } }

@yonyes yonyes added the type: enhancement A general enhancement label Sep 6, 2022
@jgrandja
Copy link
Collaborator

@yonyes

Section 3.2.2.1 Access Token Scope states the following:

The authorization server MAY fully or partially ignore the scope
requested by the client, based on the authorization server policy or
the resource owner's instructions.

Based on this, we'll consider a more lenient validation strategy.

@jgrandja jgrandja changed the title Rather than failing the request when part of the scopes aren't permitted, only return the permitted scopes Consider a lenient scope validation strategy in OAuth2ClientCredentialsAuthenticationProvider Sep 13, 2022
@jgrandja
Copy link
Collaborator

jgrandja commented Nov 18, 2022

We should consider adding OAuth2ClientCredentialsAuthenticationProvider.setAuthenticationValidator(Consumer<OAuth2ClientCredentialsAuthenticationContext> authenticationValidator), which would allow a consuming application to override the default scope validation.

The "authentication validator" feature exists in OAuth2AuthorizationCodeRequestAuthenticationProvider. See example.

@appchemist
Copy link
Contributor

appchemist commented Dec 11, 2022

I want to take this issue, @jgrandja

I have a question.

When a token request includes scopes that part of them aren't permitted and a custom lenient scope validation is used, OAuth2AuthorizationCodeRequestAuthenticationProvider can generate token with scope containing unpermitted.
So How about generating token with only permitted scopes & requested scopes by default?

@jgrandja
Copy link
Collaborator

Thanks for your interest @appchemist.

As soon as this issue is scheduled for a milestone, I'll reach out to you.

We'll be planning the features for the 1.1 release soon but I'm not sure yet if this will go into that release.

@adamleantech
Copy link
Contributor

adamleantech commented Sep 29, 2023

I'd like to upvote this request, we have a use case similar to this one with prefix scopes that we'd like to support and it would be relatively simple with a more lenient or configurable scope validation strategy. At the moment we're having to create quite an unpleasant workaround. I think a configurable strategy would be preferable

@jgrandja
Copy link
Collaborator

@adamleantech Please upvote the main issue comment.

@jgrandja
Copy link
Collaborator

This is now resolved via gh-1377.

The default scope validation can now be customized using OAuth2ClientCredentialsAuthenticationProvider.setAuthenticationValidator(Consumer<OAuth2ClientCredentialsAuthenticationContext> authenticationValidator).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
4 participants