Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FOSUserBundle and remember me

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.

like image 539
repincln Avatar asked Dec 27 '11 21:12

repincln


1 Answers

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

like image 150
Adrian C. Avatar answered Sep 29 '22 22:09

Adrian C.