Reputation: 66
I did everything as needed, yet my 'remember me' token is not set. I tracked the code until the part in /vendor/symfony/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeService.php where the cookie is set
$response->headers->setCookie(
new Cookie(
$this->options['name'],
$value,
$expires,
$this->options['path'],
$this->options['domain'],
$this->options['secure'],
$this->options['httponly']
)
);
When I do a dump of $response->headers, the cookies part looks like this:
["cookies":protected]=> array(1) { [""]=> array(1) { ["/"]=> array(1) { ["REMEMBERME"]=> object(Symfony\Component\HttpFoundation\Cookie)#753 (7) { ["name":protected]=> string(10) "REMEMBERME" ["value":protected]=> string(176) "V2Vic3BpblxVc2VyQnVuZGxlXEVudGl0eVxVc2VyOmJXRmliMmRwWlVCbmJXRnBiQzVqYjIwPToxMzM5MjQ5Mjc5OmJjY2QxMWYxNGNkZmQxZmI5ZTNjOTBhYTBiMTEyNjEwYzdkMWYxOGYwYWQzMmMzYmJhYzZlODM3Yjc0Nzc3Mjk=" ["domain":protected]=> NULL ["expire":protected]=> int(1339249279) ["path":protected]=> string(1) "/" ["secure":protected]=> bool(false) ["httpOnly":protected]=> bool(true) } } } }
The cookies array first element's key is empty. Is that correct?
And if that's correct, why is the cookie not set?
edit: My security.yml:
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
login_path: fos_user_security_login
check_path: fos_user_security_check
logout:
path: _security_logout
target: _welcome
anonymous: true
remember_me:
key: "%secret%"
lifetime: 36000
path: /
domain: ~
If you need any more information, let me know.
Upvotes: 2
Views: 1667
Reputation: 165
Just in case anyone else is also struggling with figuring out why the cookie was not being set, here's what the problem was for me.
I added the _remember_me
checkbox to my form via the builder in my LoginFormType
, which meant the field's name when rendered was actually login_form[_remember_me]
, not _remember_me
as expected.
This meant that the authentication system perceived the logins as not wanting to be remembered even when the box was checked, and hence no cookie was set. Setting the proper field name in security.yml
fixed it.
Upvotes: 1
Reputation: 66
Ok I got this fixed.
The reason had to do with my interactiveloginlistener. I listened to succesful logins, yet before the headers were sent I redirected with a new RedirectResponse, which of course didn't include the cookies.
Phew.
Upvotes: 3