function it_returns_the_provided_JWTToken(UserConverter $userProvider, JWTDecoder $JWTDecoder) { $jwtToken = new JWTToken(); $jwtToken->setToken('JWTToken'); $JWTDecoder->decode('JWTToken')->willReturn('decodedToken'); $userProvider->buildUserFromToken('decodedToken')->willReturn('AUser'); $this->authenticate($jwtToken)->shouldReturn($jwtToken); }
/** * Attempts to authenticate a TokenInterface object. * * @param TokenInterface $token The TokenInterface instance to authenticate * * @return TokenInterface An authenticated TokenInterface instance, never null * * @throws AuthenticationException if the authentication fails */ 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.'); } $decodedToken = $this->JWTDecoder->decode($token->getCredentials()); $user = $this->userConverter->buildUserFromToken($decodedToken); $token->setUser($user); return $token; }