-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Description
Before Symfony 6.2, I could programmatically login with RememberMe enabled like this:
#[Route('/register', name: 'app_register', methods: ['GET', 'POST'])]
public function register(
UserRepository $userRepository,
Request $request,
LoginFormAuthenticator $authenticator,
UserAuthenticatorInterface $userAuthenticator,
): Response
{
//...
return $userAuthenticator->authenticateUser($user, $authenticator, $request, [(new RememberMeBadge())->enable()]);
}
Symfony 6.2 added a cleaner way to programmatically login, but it doesn't support badges.
$security->login($user, LoginFormAuthenticator::class, 'main');
I'd like to suggest adding an optional parameter to $security->login()
to support badges.
Example
// symfony/security-bundle/Security.php
public function login(UserInterface $user, string $authenticatorName = null, string $firewallName = null, array $badges = []): ?Response
{
// ...
return $this->container->get('security.authenticator.managers_locator')->get($firewallName)->authenticateUser($user, $authenticator, $request, $badges);
}