-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Document how to authenticate a user "manually" #15506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So one should use |
I've been at this issue many times... namespace App\Security;
use App\Entity\User\User;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge;
/**
* Login a user programmatically.
*/
class UserAuthenticator
{
private $requestStack;
private $symfonyAuthenticator;
private $authenticator;
public function __construct(UserAuthenticatorInterface $symfonyAuthenticator, AuthenticatorInterface $authenticator, RequestStack $requestStack)
{
$this->requestStack = $requestStack;
$this->symfonyAuthenticator = $symfonyAuthenticator;
$this->authenticator = $authenticator;
}
public function loginUser(User $user): ?Response
{
$request = $this->requestStack->getMainRequest();
return $this->symfonyAuthenticator->authenticateUser($user, $this->authenticator, $request, []);
}
} The App\Security\UserAuthenticator:
autowire: true
arguments:
$authenticator: '@security.authenticator.form_login.default' |
Closing in favor of #17016. |
actually the duplicating issue is #16940 |
Scenario: You have just registered a user and you want to make sure they get the proper session cookies before you send them to their personal dashboard.
The text was updated successfully, but these errors were encountered: