Question

I'm working on a project where User can log in with a certificate.

So if there is a valid certificate in a POST request I want to login the user in a controller and redirect to the home site.

I'm using the FOSUserBundle but did not found anything that explains whether this is possible or how it's done.

Did anybody already did this or has a idea how it could be done?

Était-ce utile?

La solution

I finally found the answer.

    $token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken($user, $pw, "main", array("ROLE_USER"));
    $this->get('security.context')->setToken($token);

    $event = new \Symfony\Component\Security\Http\Event\InteractiveLoginEvent($this->getRequest(), $token);
    $this->get('event_dispatcher')->dispatch('security.interactive_login', $event);

    $user = $this->get('security.context')->getToken()->getUser();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top