Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Security/Http/Authentication/AuthenticationSuccessHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token)
return $this->handleAuthenticationSuccess($token->getUser());
}

public function handleAuthenticationSuccess(UserInterface $user, $jwt = null): Response
public function handleAuthenticationSuccess(UserInterface $user, $jwt = null, array $data = []): Response
{
if (null === $jwt) {
$jwt = $this->jwtManager->create($user);
Expand All @@ -59,8 +59,8 @@ public function handleAuthenticationSuccess(UserInterface $user, $jwt = null): R
$jwtCookies[] = $cookieProvider->createCookie($jwt);
}

$response = new JWTAuthenticationSuccessResponse($jwt, [], $jwtCookies);
$event = new AuthenticationSuccessEvent(['token' => $jwt], $user, $response);
$response = new JWTAuthenticationSuccessResponse($jwt, $data, $jwtCookies);
$event = new AuthenticationSuccessEvent(['token' => $jwt] + $data, $user, $response);

$this->dispatcher->dispatch($event, Events::AUTHENTICATION_SUCCESS);
$responseData = $event->getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ public function testHandleAuthenticationSuccessWithGivenJWT()
$this->assertSame('jwt', $content['token']);
}

public function testHandleAuthenticationSuccessWithExtraData()
{
$response = (new AuthenticationSuccessHandler($this->getJWTManager('secrettoken'), $this->getDispatcher()))
->handleAuthenticationSuccess($this->getUser(), null, ['state' => 'foo']);

$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertSame(Response::HTTP_OK, $response->getStatusCode(), $response->getContent());

$content = json_decode($response->getContent(), true);
$this->assertArrayHasKey('token', $content);
$this->assertSame('secrettoken', $content['token']);
$this->assertArrayHasKey('state', $content);
$this->assertSame('foo', $content['state']);
}

public function testOnAuthenticationSuccessSetCookie()
{
$request = $this->getRequest();
Expand Down
Loading