Elcodi\Admin\UserBundle\Security\OneTimeLoginAuthenticator::authenticateToken PHP Method

authenticateToken() public method

Authenticate the received token and returns an authenticated token.
public authenticateToken ( Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token, Symfony\Component\Security\Core\User\UserProviderInterface $userProvider, string $providerKey ) : PreAuthenticatedToken
$token Symfony\Component\Security\Core\Authentication\Token\TokenInterface The token generated with the login key.
$userProvider Symfony\Component\Security\Core\User\UserProviderInterface A user provider.
$providerKey string The security providerKey (The firewall security area)
return Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken A pre-authenticated token generated using the user admin entity.
    public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
    {
        $loginKey = $token->getCredentials();
        $user = $this->adminUserRepository->findOneBy(['oneTimeLoginHash' => $loginKey]);
        if (!$user) {
            throw new AuthenticationException(sprintf('Login Key "%s" does not exist.', $loginKey));
        }
        $user->setOneTimeLoginHash(null);
        $this->adminUserObjectManager->flush();
        return new PreAuthenticatedToken($user, $loginKey, $providerKey, $user->getRoles());
    }