Skip to content

Commit 7c26128

Browse files
gnito-orgjaviereguiluz
authored andcommitted
[Security] Add remember me description when using custom authenticator
1 parent 2525bd9 commit 7c26128

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

security/remember_me.rst

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

0 commit comments

Comments
 (0)