Pregunta

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?

¿Fue útil?

Solución

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();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top