Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit 156a6c5

Browse files
committed
bug #21136 [Security] use authenticated token for json authentication (fbourigault)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Security] use authenticated token for json authentication | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21123 | License | MIT | Doc PR | N/A When using `UsernamePasswordJsonAuthenticationListener` with [LexikJWTAuthenticationBundle](https://github.com/lexik/LexikJWTAuthenticationBundle), we get a type exception > Type error: Argument 1 passed to Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationSuccessHandler::handleAuthenticationSuccess() must implement interface Symfony\Component\Security\Core\User\UserInterface, string given, called in .../vendor/lexik/jwt-authentication-bundle/Security/Http/Authentication/AuthenticationSuccessHandler.php on line 47 This error occurs because the `UsernamePasswordJsonAuthenticationListener` send to the authentication success handler the token which have the user as a string and not the authenticated one that have a UserInterface as user. Commits ------- 208c617716 use authenticated token for json authentication
2 parents 43d8751 + 27fdeef commit 156a6c5

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Http/Firewall/UsernamePasswordJsonAuthenticationListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public function handle(GetResponseEvent $event)
101101
try {
102102
$token = new UsernamePasswordToken($username, $password, $this->providerKey);
103103

104-
$this->authenticationManager->authenticate($token);
105-
$response = $this->onSuccess($request, $token);
104+
$authenticatedToken = $this->authenticationManager->authenticate($token);
105+
$response = $this->onSuccess($request, $authenticatedToken);
106106
} catch (AuthenticationException $e) {
107107
$response = $this->onFailure($request, $e);
108108
}

Tests/Http/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\HttpKernel\KernelInterface;
1818
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
1919
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
20+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2021
use Symfony\Component\Security\Core\Exception\AuthenticationException;
2122
use Symfony\Component\Security\Core\Security;
2223
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
@@ -38,8 +39,10 @@ private function createListener(array $options = array(), $success = true)
3839
$tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock();
3940
$authenticationManager = $this->getMockBuilder(AuthenticationManagerInterface::class)->getMock();
4041

42+
$authenticatedToken = $this->getMockBuilder(TokenInterface::class)->getMock();
43+
4144
if ($success) {
42-
$authenticationManager->method('authenticate')->willReturn(true);
45+
$authenticationManager->method('authenticate')->willReturn($authenticatedToken);
4346
} else {
4447
$authenticationManager->method('authenticate')->willThrowException(new AuthenticationException());
4548
}

0 commit comments

Comments
 (0)