0

I have used FOSUser Bundle and i want to create and login user with always_remember_me cookie manually .I have tried Create a symfony2 remember me cookie manually (FOSUserBundle) but it doesn't work. i checked the cookie that FOSUSER set and it was 166B but the cookie that is bein created with functionality I have mentioned is different .please help me

in security.yml i have

encoders:
    FOS\UserBundle\Model\UserInterface: sha512

providers:
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
        logout:       true
        anonymous:    true
        remember_me:
            key: "%secret%"
            lifetime: 31104000 # in seconds
            secure: false
            always_remember_me: true

and in the Controller

    $security = $this->get('security.context');
    $providerKey = $this->container->getParameter('fos_user.firewall_name');


    $key = $this->getParameter('secret'); // your security key from parameters.yml   

    $response = new Response();
    $rememberMeToken = new RememberMeToken($user, $providerKey, $key, $user->getRoles());
    $security->setToken($rememberMeToken);
    $hash = hash('sha512', get_class($user) . $user->getUsername() . (time() + 31104000) . $user->getPassword() . $key, true);
    $str = base64_encode(get_class($user) . ':' . base64_encode($user->getUsername()) . ':' . (time() + 31104000) . ':' . $hash);
    $rememberMe = new Cookie('REMEMBERME', $str, (time() + 31104000), '/', null, false, true);
    $response->headers->setCookie($rememberMe);
    $response->send();
    return new Response('hello');

it sets remember me token but it isn't valid

Community
  • 1
  • 1
wing
  • 11
  • 3
  • It would be useful to see exactly what code you have used, and what exactly happens when you use it. – frumious Nov 06 '16 at 23:17
  • i have done whatever mentioned in http://stackoverflow.com/questions/8963470/create-a-symfony2-remember-me-cookie-manually-fosuserbundle and it sets the remember me token but it doesn't work. – wing Nov 07 '16 at 02:42
  • So you get what seems to be the correct cookie set, but the behaviour of the application isn't what you expect? – frumious Nov 08 '16 at 12:10
  • The cookie that is being set when i use fos login form is diffrent with manually cookie( they are diffrent in the size and it doesn't work correctly) – wing Nov 08 '16 at 17:25

0 Answers0