3

I'm trying to create a custom Token authenticator for my Symfony 6.2 and API Platform project

class TokenAuthenticator extends JWTTokenAuthenticator
{
    /**
     * @param PreAuthenticationJWTUserToken $preAuthToken
     * @param UserProviderInterface $userProvider
     * @return UserInterface
     */
    public function getUser($preAuthToken, UserProviderInterface $userProvider): UserInterface
    {
        $user = parent::getUser($preAuthToken, $userProvider);

        var_dump($preAuthToken->getPayload());exit;
    }
}

But I always get this error:

Attempted to load interface "AuthenticatorInterface" from namespace "Symfony\Component\Security\Guard".
Did you forget a "use" statement for "Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface"?

that means, there's no AuthenticatorInterface on Security\Guard and Http\Authenticator replaces it, so the LexikJWTAuthenticationBundle must be updated to include the new change.

This new class contains new functions so is there any documentation regarding them? Also, the purpose of establishing this class TokenAuthenticator is to make the old token invalid when changing the password, so is there a better way to do this?

sayou
  • 893
  • 8
  • 29

0 Answers0