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?

有帮助吗?

解决方案

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();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top