Skip to content

Commit 08fa59a

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Security] Add remember me description when using custom authenticator
2 parents 0e7b4f8 + fb016f7 commit 08fa59a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

security/remember_me.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,43 @@ service you created before:
346346
->tokenProvider(DoctrineTokenProvider::class)
347347
;
348348
};
349+
350+
Activating Remember Me When Using a Custom Authenticator
351+
--------------------------------------------------------
352+
353+
When you use a :doc:`custom authenticator </security/custom_authenticator>`, you
354+
must add a ``RememberMeBadge`` to the ``Passport`` for the "Remember Me" function
355+
to be activated. Without the badge, "Remember Me" will not be active, regardless
356+
of any other "Remember Me" settings.
357+
358+
For example::
359+
360+
// src/Service/LoginAuthenticator.php
361+
namespace App\Service;
362+
363+
// ...
364+
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator;
365+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
366+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge;
367+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
368+
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
369+
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
370+
371+
class LoginAuthenticator extends AbstractAuthenticator
372+
{
373+
public function authenticate(Request $request): PassportInterface
374+
{
375+
$password = $request->request->get('password');
376+
$username = $request->request->get('username');
377+
$csrfToken = $request->request->get('csrf_token');
378+
379+
return new Passport(
380+
new UserBadge($username),
381+
new PasswordCredentials($password),
382+
[
383+
new CsrfTokenBadge('login', $csrfToken),
384+
new RememberMeBadge(),
385+
]
386+
);
387+
}
388+
}

0 commit comments

Comments
 (0)