oauth2-server: v9 Client Credentials grant broken
Since version 9 the client credentials grant fills the subject of the jwt token with the client identifier
On line 56 of League\OAuth2\Server\Grant\ClientCredentialsGrant the userIdentifier is set to null
On line 107 of League\OAuth2\Server\Entities\Traits\AccessTokenTrait the SubjectIdentifier is therefor filled with de identifier of the client
When using the given jwt token: On line 132 of League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator the oauth_user_id is set to the value of sub (which is the subject identifier mentioned above)
The definition of sub says:
sub (subject): Subject of the JWT (the user)
This value if used in Line 91 of League\Bundle\OAuth2ServerBundle\Security\Authenticator checks if sub should return a NullUser if we don’t have a user, but now it doesn’t and we get an error.
I expect the SubjectIdentifier of the AccessTokenTrait should be nullable and not return the client id in the subject if we have no user. I don’t know if this has been done intentionally or my assumptions are correct.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 19 (11 by maintainers)
closing now as downstream issue has been resolved and I’ve made a change for v10 to the attribute name (although further changes will be needed before release). Thanks to all for reporting this and for the downstream fix. Apologies for the change to sub causing this
I proposed two different ways to fix the issue in the league bundle:
AccessTokenTrait::getSubjectIdentifierto restore the old behaviour: https://github.com/thephpleague/oauth2-server-bundle/pull/208/The second was approved and released and no new related issues have been raised.
I think this issue can be closed.
I’ve updated the docs to state that the user ID and client IDs should be globally unique to avoid clashes in the JWT sub.
I think I will deprecate the oauth_user_id attribute in favour of oauth_owner_id instead (naming still to be confirmed but seems sensible).
Neither of these changes fix the issues Symfony users are having. However, the behaviour change has been introduced in the AccessTokenTrait which should make it easy to remedy downstream. My thoughts just now are that in the league bundle, it should use its own implementation of the AccessTokenTrait which reinstates the old behaviour, while simultaneously making changes to ensure the client and user IDs are globally unique, so that in a later version the library can move back to the default AccessTokenTrait if it so wishes.
This seems the path of least resistance to me for now.
Hello.
Can you please let me know if this has been fixed?
I had to downgrade to thephpleague/oauth2-server-bundle v0.8 which uses league/oauth2-server v8.3 for the client credentials to work. Is there a manual fix to make it work with V9?
Here’s with v8
And here’s with v9: