我已根据需要完成了所有操作,但我的“记住我”标记尚未设置。 我跟踪代码直到 /vendor/symfony/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeService.php 设置 cookie 的位置
$response->headers->setCookie(
new Cookie(
$this->options['name'],
$value,
$expires,
$this->options['path'],
$this->options['domain'],
$this->options['secure'],
$this->options['httponly']
)
);
当我转储 $response->headers 时,cookie 部分如下所示:
["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) } } } }
cookies 数组第一个元素的键为空。这是正确的吗?
如果这是正确的,为什么没有设置 cookie?
编辑: 我的 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: ~
如果您需要更多信息,请告诉我。
最佳答案
好的,我已经解决了这个问题。
原因与我的交互式登录监听器有关。 我监听了成功的登录,但在发送 header 之前,我使用新的 RedirectResponse 进行了重定向,这当然不包括 cookie。
唷。
关于php - Symfony2 : remember me token is not set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10958187/