2

Based on this question: Automatic post-registration user authentication

$token = new UsernamePasswordToken($userEntity, null, 'main', array('ROLE_USER'));
$this->get('security.context')->setToken($token);

This worked fine on Symfony 2, but in the actual release of Symfony 2.1 this seams to do not work any more, im trying the same code but with no success (and no errors). The idea is to authenticate my user over ajax without using the login form. This because Im using this schema:

if(user_on_data_base) { 
 if(user_fb_linked_with_us) { // authenticate him and redirect to /home }
}

This is executed over ajax.

EDIT: The most strange thing is that if I execute this code from my user controller it works! but executing it from my ajax controller dont.

Community
  • 1
  • 1
DomingoSL
  • 14,920
  • 24
  • 99
  • 173

1 Answers1

0

Looking at how the HWIOAuthBundle does this, it looks like you need to throw the security.interactive_login event.

Here's how you can do it:

$this->get('event_dispatcher')->dispatch(
    SecurityEvents::INTERACTIVE_LOGIN,
    new InteractiveLoginEvent($this->container->get('request'), $token)
);
AdrienBrault
  • 7,747
  • 4
  • 31
  • 42