@@ -125,12 +125,8 @@ The ``remember_me`` firewall defines the following configuration options:
125
125
end user.
126
126
127
127
``token_provider `` (default value: ``null ``)
128
- Defines the service id of a token provider to use. By default, tokens are
129
- stored in a cookie. For example, you might want to store the token in a
130
- database, to not have a (hashed) version of the password in a cookie. The
131
- DoctrineBridge comes with a
132
- ``Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider `` that
133
- you can use.
128
+ Defines the service id of a token provider to use. If you want to store tokens
129
+ in the database, see :ref: `token_in_database `.
134
130
135
131
Forcing the User to Opt-Out of the Remember Me Feature
136
132
------------------------------------------------------
@@ -261,3 +257,116 @@ your controller using annotations::
261
257
262
258
For more information on securing services or methods in this way,
263
259
see :doc: `/security/securing_services `.
260
+
261
+ .. _token_in_database :
262
+
263
+ Storing Remember Me Tokens in the Database
264
+ ------------------------------------------
265
+
266
+ By default, tokens are stored in a cookie. You can choose to store the token in a database,
267
+ to not have a (hashed) version of the password in a cookie.
268
+ The DoctrineBridge comes with a
269
+ :class: `Symfony\\ Bridge\\ Doctrine\\ Security\\ RememberMe\\ DoctrineTokenProvider ` class
270
+ that you can use. In order to use the ``DoctrineTokenProvider ``, you first
271
+ need to register it as a service:
272
+
273
+ .. configuration-block ::
274
+
275
+ .. code-block :: yaml
276
+
277
+ # app/config/services.yml
278
+ services :
279
+ # ...
280
+
281
+ Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider : ~
282
+
283
+ .. code-block :: xml
284
+
285
+ <!-- app/config/services.xml -->
286
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
287
+ <container xmlns =" http://symfony.com/schema/dic/services"
288
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
289
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd" >
290
+
291
+ <services >
292
+ <service id =" Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider" />
293
+ </services >
294
+ </container >
295
+
296
+ .. code-block :: php
297
+
298
+ // app/config/services.php
299
+ use Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider;
300
+
301
+ $container->register(DoctrineTokenProvider::class);
302
+
303
+ The ``DoctrineTokenProvider `` makes use of a database table to store the tokens.
304
+ You need to ensure the following table exists in your database:
305
+
306
+ .. code-block :: sql
307
+
308
+ CREATE TABLE `rememberme_token` (
309
+ `series` char(88) UNIQUE PRIMARY KEY NOT NULL,
310
+ `value` char(88) NOT NULL,
311
+ `lastUsed` datetime NOT NULL,
312
+ `class` varchar(100) NOT NULL,
313
+ `username` varchar(200) NOT NULL
314
+ );
315
+
316
+ Then you need to set the ``token_provider `` option of the ``remember_me `` config
317
+ to the service you just created:
318
+
319
+ .. configuration-block ::
320
+
321
+ .. code-block :: yaml
322
+
323
+ # app/config/security.yml
324
+ security :
325
+ # ...
326
+
327
+ firewalls :
328
+ main :
329
+ # ...
330
+ remember_me :
331
+ # ...
332
+ token_provider : ' @Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider'
333
+
334
+ .. code-block :: xml
335
+
336
+ <!-- app/config/security.xml -->
337
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
338
+ <srv : container xmlns =" http://symfony.com/schema/dic/security"
339
+ xmlns : srv =" http://symfony.com/schema/dic/services"
340
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
341
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
342
+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
343
+
344
+ <config >
345
+ <!-- ... -->
346
+
347
+ <firewall name =" main" >
348
+ <!-- ... -->
349
+
350
+ <remember-me
351
+ token_profider =" @Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider"
352
+ />
353
+ </firewall >
354
+ </config >
355
+ </srv : container >
356
+
357
+ .. code-block :: php
358
+
359
+ // app/config/security.php
360
+ $container->loadFromExtension('security', [
361
+ // ...
362
+
363
+ 'firewalls' => [
364
+ 'main' => [
365
+ // ...
366
+ 'remember_me' => [
367
+ // ...
368
+ 'token_provider' => '@Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider',
369
+ ],
370
+ ],
371
+ ],
372
+ ]);
0 commit comments