1616use Symfony \Component \HttpFoundation \Response ;
1717use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
1818use Symfony \Component \Security \Core \Exception \AuthenticationException ;
19+ use Symfony \Component \Security \Core \User \AttributesBasedUserProviderInterface ;
20+ use Symfony \Component \Security \Core \User \ChainUserProvider ;
1921use Symfony \Component \Security \Core \User \UserInterface ;
2022use Symfony \Component \Security \Core \User \UserProviderInterface ;
2123use Symfony \Component \Security \Http \Authenticator \AuthenticatorInterface ;
@@ -70,6 +72,14 @@ public function authenticate(Request $request): Passport
7072
7173 /** @var string $userIdentifier */
7274 $ userIdentifier = $ psr7Request ->getAttribute ('oauth_user_id ' , '' );
75+ if ('' === $ userIdentifier ) {
76+ /**
77+ * BC layer for Symfony < 8.0
78+ */
79+ if (is_a (ChainUserProvider::class, AttributesBasedUserProviderInterface::class, true )) {
80+ throw OAuth2AuthenticationFailedException::create ('The access token has either an empty or missing "oauth_user_id" attribute. ' );
81+ }
82+ }
7383
7484 /** @var string $accessTokenId */
7585 $ accessTokenId = $ psr7Request ->getAttribute ('oauth_access_token_id ' );
@@ -81,7 +91,10 @@ public function authenticate(Request $request): Passport
8191 $ oauthClientId = $ psr7Request ->getAttribute ('oauth_client_id ' , '' );
8292
8393 $ userLoader = function (string $ userIdentifier ) use ($ oauthClientId ): UserInterface {
84- if ('' === $ userIdentifier || $ oauthClientId === $ userIdentifier ) {
94+ if (
95+ $ oauthClientId === $ userIdentifier
96+ || ('' === $ userIdentifier && is_a (ChainUserProvider::class, AttributesBasedUserProviderInterface::class, true )) // BC layer for Symfony < 8.0
97+ ) {
8598 return new ClientCredentialsUser ($ oauthClientId );
8699 }
87100
0 commit comments