From 85078622c048ceb2727d45fb05f0fdc4c3c7a49a Mon Sep 17 00:00:00 2001 From: Stefan Scheu Date: Tue, 24 Oct 2023 14:19:01 +0200 Subject: [PATCH] feat: added adapted patch for 5.4 from https://github.com/symfony/symfony/pull/48899 --- Authenticator/JsonLoginAuthenticator.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Authenticator/JsonLoginAuthenticator.php b/Authenticator/JsonLoginAuthenticator.php index 30da36aa..302e26b8 100644 --- a/Authenticator/JsonLoginAuthenticator.php +++ b/Authenticator/JsonLoginAuthenticator.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Security\Http\Authenticator; +use stdClass; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -28,6 +29,7 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface; use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PasswordUpgradeBadge; +use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials; use Symfony\Component\Security\Http\Authenticator\Passport\Passport; @@ -84,7 +86,11 @@ public function supports(Request $request): ?bool public function authenticate(Request $request): PassportInterface { try { - $credentials = $this->getCredentials($request); + $data = json_decode($request->getContent()); + if (!$data instanceof stdClass) { + throw new BadRequestHttpException('Invalid JSON.'); + } + $credentials = $this->getCredentials($data); } catch (BadRequestHttpException $e) { $request->setRequestFormat('json'); @@ -101,7 +107,8 @@ public function authenticate(Request $request): PassportInterface $passport = new Passport( new UserBadge($credentials['username'], [$this->userProvider, $method]), - new PasswordCredentials($credentials['password']) + new PasswordCredentials($credentials['password']), + [new RememberMeBadge()] ); if ($this->userProvider instanceof PasswordUpgraderInterface) { $passport->addBadge(new PasswordUpgradeBadge($credentials['password'], $this->userProvider)); @@ -154,18 +161,13 @@ public function isInteractive(): bool return true; } - public function setTranslator(TranslatorInterface $translator) + public function setTranslator(TranslatorInterface $translator): void { $this->translator = $translator; } - private function getCredentials(Request $request) + private function getCredentials(stdClass $data): array { - $data = json_decode($request->getContent()); - if (!$data instanceof \stdClass) { - throw new BadRequestHttpException('Invalid JSON.'); - } - $credentials = []; try { $credentials['username'] = $this->propertyAccessor->getValue($data, $this->options['username_path']);