1

I have made my own custom FB login function because I need a certain flow that I couldn't achieve with HWIOAuthBundle. Everything works great, except one thing... I don't know how to set remember me functionality when I log in a user through my controller.

This is the LOGIN code I've got so far:

public function loginAction() {
        // Facebook login code here
        ...

        // User already connected with FB acc. Just log in.
        $token = new UsernamePasswordToken($user, null, "main", $user->getRoles());
        $this->get("security.context")->setToken($token);

        //now dispatch the login event
        $request = $this->get("request");
        $event = new InteractiveLoginEvent($request, $token);
        $this->get("event_dispatcher")->dispatch("security.interactive_login", $event);

        // Redirect user to hime page
        return $this->redirect($this->generateUrl('/home'));
}

Thank you for any help or advice in advance!

1 Answer 1

0

You can use this remember token not the normal one it should be fixed :

$key = $this->container->getParameter('secret');
$token = new RememberMeToken($user, 'main', $key); //main is your firewall use name you gave to it.
$this->get('security.context')->setToken($token);
Sign up to request clarification or add additional context in comments.

5 Comments

This throws me a 500 error: $providerKey must not be empty. How do I set this value?
$providerKey = $this->container->getParameter('fos_user.firewall_name');
I tried switching between usernamepasswordtoken and remembermetoken but it made no difference to me, a remember me cookie is still not set, and both login the user just the same.
The class constructor has only 3 parameters: public __construct(UserInterface $user, string $providerKey, string $key). There is 4 parameters in your answer.
true confused it with the UsernamePasswordToken, i edit it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.