From c0315546f8121de51650f1b95999e92b342d21b1 Mon Sep 17 00:00:00 2001 From: Caliendo Julien <34681928+caliendojulien@users.noreply.github.com> Date: Tue, 5 Oct 2021 23:36:33 +0200 Subject: [PATCH] Update remember_me.rst Add some line to the Authenticator to add a RememberMeBadge to the Passport returned --- security/remember_me.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/security/remember_me.rst b/security/remember_me.rst index b14b012202f..bce9213336c 100644 --- a/security/remember_me.rst +++ b/security/remember_me.rst @@ -167,6 +167,29 @@ this: The user will then automatically be logged in on subsequent visits while the cookie remains valid. +Add the RememberMeBadge() to the Passport +----------------------------------------- +After uncommenting the login template and add some lines in the firewall configuration, the last thing to do is to add a new RememberMeBadge to the Password in the Authenticator. + + // src/Security/Authenticator.php + // ... + + public function authenticate(Request $request): PassportInterface + { + $email = $request->request->get('email', ''); + + $request->getSession()->set(Security::LAST_USERNAME, $email); + + return new Passport( + new UserBadge($email), + new PasswordCredentials($request->request->get('password', '')), + [ + new CsrfTokenBadge('authenticate', $request->request->get('_csrf_token')), + new RememberMeBadge(), + ] + ); + } + Forcing the User to Re-Authenticate before Accessing certain Resources ----------------------------------------------------------------------