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 if I close browser and open it after many hours. But when I load home page of my application, the cookie gets automatically deleted and I see no user logged in. Can anyone explain me the reason for cookie deletion?
remember_me:
key: qwerty
lifetime: 604800
path: /
domain: ~
This is my security.yml file section
EDIT: I have still not found the solution to this question...
EDIT2: Now got new problem. The REMEMBERME cookie does not get set at all. How to solve this??
SOLVED: see answer below
In my case I have implemented a custom Login Handler which was returning a
RedirectResponse
as per documentation. It turns out that that makes Symfony to bypass the standard login routine, and causing theREMEMBERME
cookie not been created/stored.I had to remove the Login Handler, implement a custom Login Listener with all needed logic.
You can see how to implement a Login Listener here
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:
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:
to this:
You can check it in the symfony documentation:
http://symfony.com/doc/2.7/cookbook/security/remember_me.html
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">
In my case it was a wrong implementation of the supportsClass method of my userProvider, which in turn caused an exception in the TokenBasedRememberMeService class on line 43 (thrown by getUserProvider, and catched elsewhere, thus failing silently). Digging in the path shown by Dmitry made me solve the issue.
I had the same issue. After investigation I found that :
/vendor/symfony/doctrine-bridge/Security/User/EntityUserProvider.php::loadUserByUsername()
requires to either have set theproperty
field on your entity user provider or that your repository implementsSymfony\Bridge\Doctrine\Security\User\UserLoaderInterface
and has a methodloadUserByUsername()
.I just added the property field like so :