Skip to content

Commit f8dcfdf

Browse files
committed
feature #5401 Added some more docs about the remember me feature (WouterJ)
This PR was merged into the 2.3 branch. Discussion ---------- Added some more docs about the remember me feature | Q | A | --- | --- | Doc fix? | yes | New docs? | yes | Applies to | all | Fixed tickets | - Commits ------- ce6b808 Added some more docs about the remember me feature
2 parents 07e82c4 + ce6b808 commit f8dcfdf

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

cookbook/security/remember_me.rst

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
1616
1717
# app/config/security.yml
1818
firewalls:
19-
main:
19+
default:
20+
# ...
2021
remember_me:
2122
key: "%secret%"
2223
lifetime: 604800 # 1 week in seconds
2324
path: /
25+
# by default, the feature is enabled by checking a
26+
# checkbox in the login form (see below), uncomment the
27+
# below lines to always enable it.
28+
#always_remember_me: true
2429
2530
.. code-block:: xml
2631
@@ -33,12 +38,16 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
3338
http://symfony.com/schema/dic/services/services-1.0.xsd">
3439
3540
<config>
36-
<firewall>
37-
<!-- lifetime: 604800 seconds = 1 week -->
41+
<firewall name="default">
42+
<!-- ... -->
43+
44+
<!-- by default, the feature is enabled by checking a checkbox
45+
in the login form (see below), add always-remember-me="true"
46+
to always enable it. -->
3847
<remember-me
39-
key="%secret%"
40-
lifetime="604800"
41-
path="/"
48+
key = "%secret%"
49+
lifetime = "604800" <!-- 1 week in seconds -->
50+
path = "/"
4251
/>
4352
</firewall>
4453
</config>
@@ -49,11 +58,16 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
4958
// app/config/security.php
5059
$container->loadFromExtension('security', array(
5160
'firewalls' => array(
52-
'main' => array(
61+
'default' => array(
62+
// ...
5363
'remember_me' => array(
5464
'key' => '%secret%',
5565
'lifetime' => 604800, // 1 week in seconds
5666
'path' => '/',
67+
// by default, the feature is enabled by checking a
68+
// checkbox in the login form (see below), uncomment
69+
// the below lines to always enable it.
70+
//'always_remember_me' => true,
5771
),
5872
),
5973
),
@@ -103,21 +117,30 @@ The ``remember_me`` firewall defines the following configuration options:
103117
"Remember Me" feature is always enabled, regardless of the desire of the
104118
end user.
105119

120+
``token_provider`` (default value: ``null``)
121+
Defines the service id of a token provider to use. By default, tokens are
122+
stored in a cookie. For example, you might want to store the token in a
123+
database, to not have a (hashed) version of the password in a cookie. The
124+
DoctrineBridge comes with a
125+
``Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider`` that
126+
you can use.
127+
106128
Forcing the User to Opt-Out of the Remember Me Feature
107129
------------------------------------------------------
108130

109131
It's a good idea to provide the user with the option to use or not use the
110132
remember me functionality, as it will not always be appropriate. The usual
111133
way of doing this is to add a checkbox to the login form. By giving the checkbox
112-
the name ``_remember_me``, the cookie will automatically be set when the checkbox
113-
is checked and the user successfully logs in. So, your specific login form
114-
might ultimately look like this:
134+
the name ``_remember_me`` (or the name you configured using ``remember_me_parameter``),
135+
the cookie will automatically be set when the checkbox is checked and the user
136+
successfully logs in. So, your specific login form might ultimately look like
137+
this:
115138

116139
.. configuration-block::
117140

118141
.. code-block:: html+jinja
119142

120-
{# src/Acme/SecurityBundle/Resources/views/Security/login.html.twig #}
143+
{# app/Resources/views/security/login.html.twig #}
121144
{% if error %}
122145
<div>{{ error.message }}</div>
123146
{% endif %}
@@ -137,7 +160,7 @@ might ultimately look like this:
137160

138161
.. code-block:: html+php
139162

140-
<!-- src/Acme/SecurityBundle/Resources/views/Security/login.html.php -->
163+
<!-- app/Resources/views/security/login.html.php -->
141164
<?php if ($error): ?>
142165
<div><?php echo $error->getMessage() ?></div>
143166
<?php endif ?>
@@ -159,7 +182,7 @@ might ultimately look like this:
159182
The user will then automatically be logged in on subsequent visits while
160183
the cookie remains valid.
161184

162-
Forcing the User to Re-authenticate before Accessing certain Resources
185+
Forcing the User to Re-Authenticate before Accessing certain Resources
163186
----------------------------------------------------------------------
164187

165188
When the user returns to your site, they are authenticated automatically based

0 commit comments

Comments
 (0)