/** * @param AccessToken $accessToken * @param UriInterface $destination * @return Response */ public function handle(AccessToken $accessToken, UriInterface $destination) { $claims = $this->userService->getUserClaims($accessToken)->toArray(); $jwt = $this->encoderService->encode($claims); $q = $destination->getQuery(); $q .= ($q ? '&' : '') . 'jwt=' . $jwt; return new RedirectResponse((string) $destination->withQuery($q)); }
/** * @test */ public function it_returns_a_redirect_response_to_the_destination_with_a_jwt_as_url_fragment() { $userId = new StringLiteral('id-1'); $accessToken = new AccessToken($userId->toNative(), new TokenCredentials('token', 'secret')); $destination = new Uri('http://bar.com/sub/directory?query=value'); $userClaims = new UserClaims($userId, new StringLiteral('foo'), new EmailAddress('*****@*****.**')); $jwt = new Jwt(['alg' => 'mocked'], $userClaims->toArray(), new Signature('gibberish'), ['headers', 'body', 'gibberish']); $expectedDestination = 'http://bar.com/sub/directory?query=value&jwt=headers.body.gibberish'; $this->userService->expects($this->once())->method('getUserClaims')->with($accessToken)->willReturn($userClaims); $this->encoder->expects($this->once())->method('encode')->with($userClaims->toArray())->willReturn($jwt); $response = $this->callbackHandler->handle($accessToken, $destination); /* @var RedirectResponse $response */ $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertEquals($expectedDestination, $response->getTargetUrl()); }