Exemple #1
0
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     if (!$userProvider instanceof TokenUserProviderInterface) {
         throw new \InvalidArgumentException('$userProvider must be an instance of "Antenna\\TokenUserProviderInterface".');
     }
     // Credentials is an encoded JWT token, therefor use JWT::decode() in order to get the correct
     // token information.
     // I really want an actual Token object
     $token = $token->getToken();
     if ($token->exp < time()) {
         throw new BadCredentialsException('Token have expired.');
     }
     $user = $userProvider->loadUserByToken($token->sub);
     $this->userChecker->checkPreAuth($user);
     $this->userChecker->checkPostAuth($user);
     return (new Token($providerKey, $token, $user->getRoles()))->setAuthenticated(true)->setUser($user);
 }