Token was deauthenticated after trying to refresh it

As of Symfony 4.0, logout_on_user_change is set to true. That means a user will be logged out if it has been changed. You should implement Symfony\Component\Security\Core\User\EquatableInterface and add the isEqualTo method: class User implements EquatableInterface { public function isEqualTo(UserInterface $user) { if ($this->password !== $user->getPassword()) { return false; } if ($this->salt !== $user->getSalt()) { return … Read more

How to check if a user is logged in Symfony2 inside a controller?

Warning: Checking for ‘IS_AUTHENTICATED_FULLY’ alone will return false if the user has logged in using “Remember me” functionality. According to Symfony 2 documentation, there are 3 possibilities: IS_AUTHENTICATED_ANONYMOUSLY – automatically assigned to a user who is in a firewall protected part of the site but who has not actually logged in. This is only possible … Read more

How to programmatically login/authenticate a user?

Yes, you can do this via something similar to the following: use Symfony\Component\EventDispatcher\EventDispatcher, Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken, Symfony\Component\Security\Http\Event\InteractiveLoginEvent; public function registerAction() { // … if ($this->get(“request”)->getMethod() == “POST”) { // … Do any password setting here etc $em->persist($user); $em->flush(); // Here, “public” is the name of the firewall in your security.yml $token = new UsernamePasswordToken($user, $user->getPassword(), “public”, $user->getRoles()); … Read more