I'm trying to implement single sign on access to a website using Symfony2.
The authentication itself seems to work fine, but only for the initial page. On the next page that is loaded the user is not logged in anymore.
Relevant code:
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$event = new InteractiveLoginEvent($request, $token);
$this->get("event_dispatcher")->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $event);
$this->get("security.context")->setToken($token);
return $this->redirect($this->generateUrl('sonata_user_profile_show'));
First page (without the redirect):
Second page: