From ce4deb24f86c0275297bc561422a860026e37195 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Wed, 25 Jan 2023 22:18:55 +0100 Subject: [PATCH] feat(upgrade): add compliance with symfony 6.2 --- .../Authenticator/LoginFormAuthenticator.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/core/Authenticator/LoginFormAuthenticator.php b/src/core/Authenticator/LoginFormAuthenticator.php index f96c1ef..6a7dcdf 100644 --- a/src/core/Authenticator/LoginFormAuthenticator.php +++ b/src/core/Authenticator/LoginFormAuthenticator.php @@ -18,6 +18,10 @@ use Symfony\Component\Security\Csrf\CsrfToken; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Component\Security\Http\Util\TargetPathTrait; use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator; +use Symfony\Component\Security\Http\Authenticator\Passport\Passport; +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\Badge\CsrfTokenBadge; class LoginFormAuthenticator extends AbstractLoginFormAuthenticator { @@ -44,6 +48,21 @@ class LoginFormAuthenticator extends AbstractLoginFormAuthenticator return 'auth_login' === $request->attributes->get('_route') && $request->isMethod('POST'); } + public function authenticate(Request $request): Passport + { + $id = $request->request->get('id', ''); + + $request->getSession()->set(Security::LAST_USERNAME, $id); + + return new Passport( + new UserBadge($id), + new PasswordCredentials($request->request->get('password', '')), + [ + new CsrfTokenBadge('authenticate', $request->request->get('_csrf_token')), + ] + ); + } + public function getCredentials(Request $request) { $credentials = [