public function it_should_throw_a_JWTNotFoundException_if_no_token_is_found(JWTRetrievalStrategyInterface $strategy1, JWTRetrievalStrategyInterface $strategy2, JWTRetrievalStrategyInterface $strategy3) { $request = new Request(); $strategy1->getToken($request)->shouldBeCalled()->willThrow(JWTNotFoundException::class); $strategy2->getToken($request)->shouldBeCalled()->willThrow(JWTNotFoundException::class); $strategy3->getToken($request)->shouldBeCalled()->willThrow(JWTNotFoundException::class); $this->shouldThrow(JWTNotFoundException::class)->duringGetToken($request); }
function it_authenticates_if_a_token_is_found(AuthenticationManagerInterface $authenticationManager, JWTRetrievalStrategyInterface $jwtRetrievalStrategy, GetResponseEvent $event) { $request = new Request(); $event->getRequest()->willReturn($request); $jwtRetrievalStrategy->getToken($request)->willReturn('JWTToken'); $jwtToken = new JWTToken(); $jwtToken->setToken('JWTToken'); $this->handle($event); $authenticationManager->authenticate($jwtToken)->shouldBeCalled(); }
/** * This interface must be implemented by firewall listeners. * * @param GetResponseEvent $event */ public function handle(GetResponseEvent $event) { try { $jwtTokenValue = $this->jwtRetrievalStrategy->getToken($event->getRequest()); } catch (JWTNotFoundException $e) { return; } $jwtToken = new JWTToken(); $jwtToken->setToken($jwtTokenValue); $authToken = $this->authenticationManager->authenticate($jwtToken); $this->tokenStorage->setToken($authToken); }