コード例 #1
0
 function it_returns_the_provided_JWTToken(JWTUserBuilder $JWTUserBuilder)
 {
     $jwtToken = new JWTToken();
     $jwtToken->setToken('JWTToken');
     $JWTUserBuilder->buildUserFromToken('JWTToken')->willReturn('AUser');
     $this->authenticate($jwtToken)->shouldReturn($jwtToken);
 }
コード例 #2
0
 /**
  * Attempts to authenticate a TokenInterface object.
  *
  * @param TokenInterface $token The TokenInterface instance to authenticate
  *
  * @throws AuthenticationException if the authentication fails
  * @return TokenInterface An authenticated TokenInterface instance, never null
  *
  */
 public function authenticate(TokenInterface $token)
 {
     if (!$token instanceof JWTToken) {
         throw new AuthenticationException(sprintf('%s works only for JWTToken', __CLASS__));
     }
     if (!$token->getCredentials()) {
         throw new AuthenticationException('JWTToken must contain a token in order to authenticate.');
     }
     try {
         $user = $this->userBuilder->buildUserFromToken($token->getCredentials());
     } catch (JWTDecodeUnexpectedValueException $e) {
         throw new AuthenticationException('Failed to decode the JWT');
     }
     $token->setUser($user);
     return $token;
 }