Skip to content

Commit fb016f7

Browse files
committed
Merge branch '5.3' into 5.4
* 5.3: [Security] Add remember me description when using custom authenticator
2 parents 225dc1c + 09b9115 commit fb016f7

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
@@ -354,3 +354,43 @@ 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 :doc:`custom authenticator </security/custom_authenticator>`, you
362+
must add a ``RememberMeBadge`` to the ``Passport`` for the "Remember Me" function
363+
to be activated. Without the badge, "Remember Me" will not be active, regardless
364+
of any other "Remember Me" settings.
365+
366+
For example::
367+
368+
// src/Service/LoginAuthenticator.php
369+
namespace App\Service;
370+
371+
// ...
372+
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator;
373+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
374+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge;
375+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
376+
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
377+
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
378+
379+
class LoginAuthenticator extends AbstractAuthenticator
380+
{
381+
public function authenticate(Request $request): PassportInterface
382+
{
383+
$password = $request->request->get('password');
384+
$username = $request->request->get('username');
385+
$csrfToken = $request->request->get('csrf_token');
386+
387+
return new Passport(
388+
new UserBadge($username),
389+
new PasswordCredentials($password),
390+
[
391+
new CsrfTokenBadge('login', $csrfToken),
392+
new RememberMeBadge(),
393+
]
394+
);
395+
}
396+
}

0 commit comments

Comments
 (0)