@@ -37,12 +37,12 @@ public function authenticateToken(TokenInterface $token, UserProviderInterface $
3737 );
3838 }
3939
40- $ errorCode = $ this ->container ->getParameter ('token_authenticator.error_codes ' )['invalid_token ' ];
41- $ apiKey = $ token ->getCredentials ();
42- $ token = $ userProvider ->findTokenByApiKey ($ apiKey );
40+ $ errorCode = $ this ->container ->getParameter ('token_authenticator.error_codes ' )['invalid_token ' ];
41+ $ tokenString = $ token ->getCredentials ();
42+ $ token = $ userProvider ->findTokenByApiKey ($ tokenString );
4343
4444 if (!$ token ) {
45- throw new NotValidTokenException (sprintf ('API Key "%s" does not exist. ' , $ apiKey ), $ errorCode );
45+ throw new NotValidTokenException (sprintf ('API Key "%s" does not exist. ' , $ tokenString ), $ errorCode );
4646 }
4747
4848 if ($ token ->getStatus () == AccessToken::STATUS_DENIED ) {
@@ -62,7 +62,7 @@ public function authenticateToken(TokenInterface $token, UserProviderInterface $
6262 throw new NotValidTokenException ('User of this token not exist ' , $ errorCode );
6363 }
6464
65- return new PreAuthenticatedToken ($ user , $ apiKey , $ providerKey , $ user ->getRoles ());
65+ return new PreAuthenticatedToken ($ user , $ tokenString , $ providerKey , $ user ->getRoles ());
6666 }
6767
6868 public function supportsToken (TokenInterface $ token , $ providerKey )
@@ -72,13 +72,11 @@ public function supportsToken(TokenInterface $token, $providerKey)
7272
7373 public function createToken (Request $ request , $ providerKey )
7474 {
75- $ apiKey = $ request ->headers ->get ('apikey ' );
76- if (!$ apiKey ) {
77- $ apiKey = $ request ->headers ->get ('accesstoken ' );
78- }
75+ $ tokenField = $ this ->container ->getParameter ('token_authenticator.token_field ' );
76+ $ tokenString = $ request ->headers ->get ($ tokenField );
7977
80- if ($ apiKey ) {
81- return new PreAuthenticatedToken ('anon. ' , $ apiKey , $ providerKey );
78+ if ($ tokenString ) {
79+ return new PreAuthenticatedToken ('anon. ' , $ tokenString , $ providerKey );
8280 }
8381
8482 return null ;
0 commit comments