FOSUserBundle 并记住我
我在 Symfony2 中使用 FOSUserBundle 进行身份验证。除了“记住我”之外,一切正常。我的 security.yml 看起来像这样:
security:
providers:
fos_userbundle:
id: fos_user.user_manager
encoders:
'FOS\UserBundle\Model\UserInterface': sha512
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
logout: true
anonymous: true
remember_me:
key: aSecretKey
lifetime: 3600
path: /
domain: ~
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, role: ROLE_ADMIN }
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
有谁知道如何解决这个问题。
I'm using a FOSUserBundle for authentication in Symfony2. Everything works fine except "remember me". My security.yml looks like this:
security:
providers:
fos_userbundle:
id: fos_user.user_manager
encoders:
'FOS\UserBundle\Model\UserInterface': sha512
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
logout: true
anonymous: true
remember_me:
key: aSecretKey
lifetime: 3600
path: /
domain: ~
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, role: ROLE_ADMIN }
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
Does anybody know how to solve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这对我来说不起作用,因为我使用了 2 个用户提供商:FOSUserBundle 和 FosFacebook。
实际上已经设置了 cookie,但在 TokenBasedRememberMeServices、processAutoLoginCookie 中,我发现使用了错误的提供程序。
要修复它,我必须在 Remember_me 部分的 security.yml 中指定我想要使用的提供程序。
也许这也对其他人有帮助。
更新:我修改了响应,因为在较新版本的 Symfony 中,remember_me 下的“key”现在称为“secret”。
This was not working for me neither because i used 2 user providers: FOSUserBundle and FosFacebook.
The cookie was actually being set, but in TokenBasedRememberMeServices, processAutoLoginCookie i saw that the wrong provider was being used.
To fix it i had to specify in security.yml in remember_me section the provider i wanted to use.
Maybe this helps somebody else too.
Update: I've modified the response since in newer versions of Symfony, the "key" under remember_me is now called "secret".
正如“Adrian C”所说,但做了一些对我有用的改变。
我用“秘密”代替“钥匙”
As "Adrian C" said, but with a little change which worked for me.
instead "key" i used "secret"
如果浏览器无法在您的
域
(例如localhost
)上设置cookie,记住我
功能可能无法工作。如果是这种情况,请将您的域设置为有效的域名(例如,dev.site.com
)。另请确保您已清除缓存。Remember me
feature may not work if browser can't set cookies on yourdomain
(localhost
, for example). If this is a case, then setup your domain as a valid domain name (eg,dev.site.com
). Also make sure you have cleared cache.它对我来说适用于会话生命周期以及安全性 remenber_me 配置:
It's working for me with session lifetime in add of security remenber_me configuration: