I am new to Symfony so it may well be that my question is the result of a simple error but I have been searching for an answer for quite a while with no success.
I am trying to log in a user that requests for a new password with a temporary token.
The relevant part of my controller is:
// auto log in the user
$token = new UsernamePasswordToken($user, $user->getPassword(), 'main', $user->getRoles());
$this->get("security.context")->setToken($token);
// do the the login event
$event = new InteractiveLoginEvent($request, $token);
$this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
return $this->redirect($this->generateUrl('nononsense_home_homepage'));
If I get the user info with getUser before the redirect I can see that the credentials of the logged user are there but they are lost as soon as the redirect takes place.
Curiously enough if I purposedly include an error in the target page whenever symfony throws the errror I can check theat I am logged with the right credentials in the symfony dev bar!!! But if I correct the error and reload the page again I can see in the dev bar that the user is not authenticated any longer.
Firewall
main:
pattern: ^/
provider: main
form_login:
check_path: /users/check_user
login_path: /users/login
remember_me: true
default_target_path: /users/login_init
logout:
path: /users/logout
target: /
remember_me:
key: Qn65f7wtgGZKCCzWQZps04AskmNSiZrvl3qVZRCCIp
lifetime: 31536000
path: /
domain: ~
anonymous: false
switch_user: true
If you need any other chunk of code just let me know...