Problem/Motivation
Return invalid_scope error when refresh token second time.
{
"error": "invalid_scope",
"error_description": "The requested scope is invalid, unknown, or malformed",
"hint": "Check the `role_authenticated` scope"
}
This problem is caused by thephpleague/oauth2-server, RefreshTokenGrant doesn't provides a user identifier.
https://github.com/thephpleague/oauth2-server/blob/00323013403e1a1e0f424...
And ScopeRepository of simple_oauth return empty of scope directly if no user identifier is provided.
https://git.drupalcode.org/project/simple_oauth/-/blob/6.0.x/src/Reposit...
Steps to reproduce
1, Request a access_token use any grant type.
2, Refresh the access_token through the refresh_token grant type.
3, Refresh the access_token again through the refresh_token grant type, which refresh token was generate in step 2.
4, We can see the 400 with :
{
"error": "invalid_scope",
"error_description": "The requested scope is invalid, unknown, or malformed",
"hint": "Check the `role_authenticated` scope"
}
Proposed resolution
Change ScopeRepository to return method inputed scopes as default if the grant type is refresh_token even no user identifier is provided.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | issues-3509299.patch | 911 bytes | 司南 |
Issue fork simple_oauth-3509299
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
司南 commentedComment #4
司南 commentedFeel free to use this patch.
Comment #5
bojan_dev commentedI can't reproduce this, it's not possible to refresh the token for any grant type, it is only applicable for the "Authorization Code".
Can you please provide more info about the configured consumer, scope and authorize request?
By the way: please don't set the issue status to reviewed, a peer review should not be done on your own work.
Comment #6
idebr commentedCan you check the Grant type 'Refresh Token' is enabled on your Consumer edit form?
Comment #7
司南 commentedI use a custom grant type which like the deprecated grant type
password.Comment #8
司南 commentedConsumer created by the lines:
Scope config entity I use:
Generate access token:
Refresh the token: (Do this twice cause the error)
Comment #9
司南 commented#5 @bojan_dev
Why is it not possible to refresh the token for any grant type, it is only applicable for the "Authorization Code"?
Is there any oauth2 protocol pointting this?
Comment #10
bojan_dev commentedI was assuming you were only using the grant types that are provided by simple_oauth, based on that assumption that would mean that only the Authorization code grant type supports refresh tokens. But I see you are using the Password grant, which is not supported by simple_oauth: 6.0 due to the following reason: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#s...
You could take a look in 5.2 which still supports the password grant.
Comment #11
m.stenta@司南 I'm not sure if this is related, but I just ran into this issue with the
simple_oauth_password_grantmodule after updating tosimple_oauth6.0.0-beta10: #3511488: Refreshed access_token is missing scope with league/oauth2-server ^9Comment #12
m.stentaI just tested the change proposed by @司南 and it fixes the issue in #3511488: Refreshed access_token is missing scope with league/oauth2-server ^9!
So maybe it's all the same bug in
simple_oauthafter all.Setting this back to Needs Review.
@bojan_dev please see the steps to reproduce and screenshots in #3511488: Refreshed access_token is missing scope with league/oauth2-server ^9 - even though it is in the other module's issue queue, the fix proposed by @司南 fixes what I am seeing.
It makes me wonder if Authorization code grant types are affected too - I haven't tested them. It's very easy to test the password grant issue and see the missing scope in the Simple OAuth UI.
Comment #14
bojan_dev commentedIt appears the following change in thephpleague/oauth2-server is the reason for the BC: https://github.com/thephpleague/oauth2-server/pull/1094.
finalizeScopesis now being called in the RefreshTokenGrant, which does not set the$userIdentifier, this means that no scopes are being returned. This has impact on all grant types that support refresh tokens. Sorry that I missed this, also I have read your comments @m.stenta on #3277256: Move to thephpleague/oauth2-server 9.0, those are valid points I will definitely make a major version release next time.Merging MR !176 and will roll out a new stable release.
Comment #16
bojan_dev commentedComment #17
bojan_dev commentedComment #18
m.stentaThank you @bojan_dev! I appreciate everything you do for this module (and Drupal generally)! I am truly grateful!