Skip to content

Commit 34eea80

Browse files
committed
minor #16202 [Security] Add remember me description when using custom authenticator (gnito-org)
This PR was squashed before being merged into the 5.3 branch. Discussion ---------- [Security] Add remember me description when using custom authenticator This PR solves #16149. <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `5.x` for features of unreleased versions). --> Commits ------- 7c26128 [Security] Add remember me description when using custom authenticator
2 parents 17dec97 + 7c26128 commit 34eea80

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

security/remember_me.rst

+39
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)