/**
  * {@inheritdoc}
  */
 public function authenticate(TokenInterface $token)
 {
     if (!($payload = $this->jwtManager->decode($token))) {
         throw new AuthenticationException('Invalid JWT Token');
     }
     $user = $this->getUserFromPayload($payload);
     $authToken = new JWTUserToken($user->getRoles());
     $authToken->setUser($user);
     $authToken->setRawToken($token->getCredentials());
     $event = new JWTAuthenticatedEvent($payload, $authToken);
     $this->dispatcher->dispatch(Events::JWT_AUTHENTICATED, $event);
     return $authToken;
 }
Beispiel #2
0
 /**
  * Authenticate a user via a JWT token.
  *
  * @param User $user
  *
  * @Given I authenticate myself as :user
  */
 public function authenticateAs(User $user)
 {
     $client = $this->getSession()->getDriver()->getClient();
     $token = $this->jwtManager->create($user);
     $client->setServerParameter('HTTP_AUTHORIZATION', sprintf('Bearer %s', $token));
 }