FOSUserBundle 并记住我

发布于 2024-12-23 02:51:28 字数 876 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

忆梦 2024-12-30 02:51:28

这对我来说不起作用,因为我使用了 2 个用户提供商:FOSUserBundle 和 FosFacebook。

实际上已经设置了 cookie,但在 TokenBasedRememberMeServices、processAutoLoginCookie 中,我发现使用了错误的提供程序。

要修复它,我必须在 Remember_me 部分的 security.yml 中指定我想要使用的提供程序。

firewalls:
    main:
        ...
        remember_me:
            secret:      "%secret%"
            lifetime: 2592000
            path:     /
            domain:   ~
            user_provider: fos_userbundle

也许这也对其他人有帮助。

更新:我修改了响应,因为在较新版本的 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.

firewalls:
    main:
        ...
        remember_me:
            secret:      "%secret%"
            lifetime: 2592000
            path:     /
            domain:   ~
            user_provider: fos_userbundle

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".

贵在坚持 2024-12-30 02:51:28

正如“Adrian C”所说,但做了一些对我有用的改变。

我用“秘密”代替“钥匙”

 firewalls:
     main:
         ...
         remember_me:
             secret:      "%secret%"
             lifetime: 2592000
             path:     /
             domain:   ~
             user_provider: fos_userbundle

As "Adrian C" said, but with a little change which worked for me.

instead "key" i used "secret"

 firewalls:
     main:
         ...
         remember_me:
             secret:      "%secret%"
             lifetime: 2592000
             path:     /
             domain:   ~
             user_provider: fos_userbundle
留蓝 2024-12-30 02:51:28

如果浏览器无法在您的(例如localhost)上设置cookie,记住我功能可能无法工作。如果是这种情况,请将您的域设置为有效的域名(例如,dev.site.com)。另请确保您已清除缓存。

Remember me feature may not work if browser can't set cookies on your domain (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.

淡淡の花香 2024-12-30 02:51:28

它对我来说适用于会话生命周期以及安全性 remenber_me 配置:

  framework:
    session:
        default_locale: %locale%
        auto_start:     true
        lifetime:       3600

It's working for me with session lifetime in add of security remenber_me configuration:

  framework:
    session:
        default_locale: %locale%
        auto_start:     true
        lifetime:       3600
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文