Skip to content

Commit 2df2275

Browse files
parijkewouterj
authored andcommitted
Added the way to activate remember me in the new authentication system
I had to search a while for myself not understanding why I did not have a REMEMBERME cookie when I activated the new system. So maybe handy to add it.
1 parent d36b949 commit 2df2275

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

security/remember_me.rst

+18-19
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,25 @@ the cookie remains valid.
169169

170170
Add the RememberMeBadge() to the Passport
171171
-----------------------------------------
172-
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.
173172

174-
// src/Security/Authenticator.php
175-
// ...
176-
177-
public function authenticate(Request $request): PassportInterface
178-
{
179-
$email = $request->request->get('email', '');
180-
181-
$request->getSession()->set(Security::LAST_USERNAME, $email);
182-
183-
return new Passport(
184-
new UserBadge($email),
185-
new PasswordCredentials($request->request->get('password', '')),
186-
[
187-
new CsrfTokenBadge('authenticate', $request->request->get('_csrf_token')),
188-
new RememberMeBadge(),
189-
]
190-
);
191-
}
173+
Beware that in the new Authenitaction System you have to set the RememberMeBadge()
174+
in the authenticate method of the authenticator, like::
175+
176+
public function authenticate(Request $request): PassportInterface
177+
{
178+
$email = $request->request->get('email', '');
179+
180+
$request->getSession()->set(Security::LAST_USERNAME, $email);
181+
182+
return new Passport(
183+
new UserBadge($email),
184+
new PasswordCredentials($request->request->get('password', '')),
185+
[
186+
new CsrfTokenBadge('authenticate', $request->get('_csrf_token')),
187+
new RememberMeBadge(),
188+
]
189+
);
190+
}
192191

193192
Forcing the User to Re-Authenticate before Accessing certain Resources
194193
----------------------------------------------------------------------

0 commit comments

Comments
 (0)