Remember Me functionality not working in Symfony2

前端 未结 10 1260
鱼传尺愫
鱼传尺愫 2020-12-14 21:44

I have implemented remember me functionality in Symfony2. When I log in with remember me box checked, cookie named \"REMEMBERME\" gets created. That cookie is also available

相关标签:
10条回答
  • 2020-12-14 21:50

    Although this question has already been answered, I would like to contribute a possible solution, if only for posterity and Google search referrals for this problem :)

    "The issue is simple: a remembered used does not have the IS_AUTHENTICATED_FULLY role but only IS_AUTHENTICATED_REMEMBERED to make a difference between a remembered user and a user who logged in"

    Source: http://www.mail-archive.com/symfony-users@googlegroups.com/msg34021.html

    What this means is that in your security configuration, you must make sure that for every ACL entry the IS_AUTHENTICATED_REMEMBERED role is configured in addition to the IS_AUTHENTICATED_FULLY role.

    For example:

    #app/config/security.yml
    security:
        ...
        access_control:
            - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/admin/, role: [IS_AUTHENTICATED_FULLY,IS_AUTHENTICATED_REMEMBERED] }
    
    0 讨论(0)
  • 2020-12-14 21:52

    I had the same issue. After investigation I found that : /vendor/symfony/doctrine-bridge/Security/User/EntityUserProvider.php::loadUserByUsername() requires to either have set the property field on your entity user provider or that your repository implements Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface and has a method loadUserByUsername().

    I just added the property field like so :

    providers:
        user_provider:
            entity:
                class: App\Entity\User
                property: email
    
    0 讨论(0)
  • 2020-12-14 21:56

    In my case, the authenticators was overided with the method supportsRememberMe:

    public function supportsRememberMe()
    {
        return true; // change it to true
    }
    
    0 讨论(0)
  • 2020-12-14 21:59

    I had this problem and the issue was that I did not use single quotation marks in the property key of remember_me section (security.yml).

    Change this:

    remember_me:
        key:      qwerty
        lifetime: 604800
        path:     /
        domain:   ~
    

    to this:

    remember_me:
        key:      'qwerty'
        lifetime: 604800
        path:     /
        domain:   ~
    


    You can check it in the symfony documentation:
    http://symfony.com/doc/2.7/cookbook/security/remember_me.html

    0 讨论(0)
  • 2020-12-14 22:01

    try to increase your session lifetime: (config.yml)

      framework:
        session:
            default_locale: %locale%
            auto_start:     true
            lifetime:       604800
    
    0 讨论(0)
  • 2020-12-14 22:02

    I'm using Symfony 4 and I had a similar problem, the REMEMBERME cookies was not set.

    My issue was that I had a value="" set to the input type checkbox field.

    So I changed from this

    <input type="checkbox" value="" id="remember_me" name="_remember_me">

    to this

    <input type="checkbox" id="remember_me" name="_remember_me">

    0 讨论(0)
提交回复
热议问题