@@ -22,8 +22,8 @@ Your exact situation may differ, but in this example, a token is read
22
22
from an ``apikey `` query parameter, the proper username is loaded from that
23
23
value and then a User object is created::
24
24
25
- // src/Acme/HelloBundle /Security/ApiKeyAuthenticator.php
26
- namespace Acme\HelloBundle \Security;
25
+ // src/AppBundle /Security/ApiKeyAuthenticator.php
26
+ namespace AppBundle \Security;
27
27
28
28
use Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface;
29
29
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@@ -147,8 +147,8 @@ used by Symfony's core user provider system).
147
147
148
148
The ``$userProvider `` might look something like this::
149
149
150
- // src/Acme/HelloBundle /Security/ApiKeyUserProvider.php
151
- namespace Acme\HelloBundle \Security;
150
+ // src/AppBundle /Security/ApiKeyUserProvider.php
151
+ namespace AppBundle \Security;
152
152
153
153
use Symfony\Component\Security\Core\User\UserProviderInterface;
154
154
use Symfony\Component\Security\Core\User\User;
@@ -192,6 +192,44 @@ The ``$userProvider`` might look something like this::
192
192
}
193
193
}
194
194
195
+ No register your user provider as service.
196
+
197
+ .. configuration-block ::
198
+
199
+ .. code-block :: yaml
200
+
201
+ # app/config/services.yml
202
+ services :
203
+ api_key_user_provider :
204
+ class : AppBundle\Security\ApiKeyUserProvider
205
+
206
+ .. code-block :: xml
207
+
208
+ <!-- app/config/services.xml -->
209
+ <?xml version =" 1.0" ?>
210
+ <container xmlns =" http://symfony.com/schema/dic/services"
211
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
212
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
213
+ http://symfony.com/schema/dic/services/services-1.0.xsd" >
214
+ <services >
215
+ <!-- ... -->
216
+
217
+ <service id =" api_key_user_provider"
218
+ class =" AppBundle\Security\ApiKeyUserProvider" />
219
+ </services >
220
+ </container >
221
+
222
+ .. code-block :: php
223
+
224
+ // app/config/services.php
225
+ use Symfony\Component\DependencyInjection\Definition;
226
+
227
+ // ...
228
+
229
+ $container->setDefinition('api_key_user_provider', new Definition(
230
+ 'AppBundle\Security\ApiKeyUserProvider',
231
+ ));
232
+
195
233
.. note ::
196
234
197
235
Read the dedicated article to learn
@@ -231,8 +269,8 @@ you can use to create an error ``Response``.
231
269
232
270
.. code-block :: php
233
271
234
- // src/Acme/HelloBundle /Security/ApiKeyAuthenticator.php
235
- namespace Acme\HelloBundle \Security;
272
+ // src/AppBundle /Security/ApiKeyAuthenticator.php
273
+ namespace AppBundle \Security;
236
274
237
275
use Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface;
238
276
use Symfony\Component\Security\Core\Exception\AuthenticationException;
@@ -270,8 +308,8 @@ your custom user provider as a service called ``your_api_key_user_provider``
270
308
# ...
271
309
272
310
apikey_authenticator :
273
- class : Acme\HelloBundle \Security\ApiKeyAuthenticator
274
- arguments : ["@your_api_key_user_provider "]
311
+ class : AppBundle \Security\ApiKeyAuthenticator
312
+ arguments : ["@api_key_user_provider "]
275
313
276
314
.. code-block :: xml
277
315
@@ -285,9 +323,9 @@ your custom user provider as a service called ``your_api_key_user_provider``
285
323
<!-- ... -->
286
324
287
325
<service id =" apikey_authenticator"
288
- class =" Acme\HelloBundle \Security\ApiKeyAuthenticator"
326
+ class =" AppBundle \Security\ApiKeyAuthenticator"
289
327
>
290
- <argument type =" service" id =" your_api_key_user_provider " />
328
+ <argument type =" service" id =" api_key_user_provider " />
291
329
</service >
292
330
</services >
293
331
</container >
@@ -301,8 +339,8 @@ your custom user provider as a service called ``your_api_key_user_provider``
301
339
// ...
302
340
303
341
$container->setDefinition('apikey_authenticator', new Definition(
304
- 'Acme\HelloBundle \Security\ApiKeyAuthenticator',
305
- array(new Reference('your_api_key_user_provider '))
342
+ 'AppBundle \Security\ApiKeyAuthenticator',
343
+ array(new Reference('api_key_user_provider '))
306
344
));
307
345
308
346
Now, activate it in the ``firewalls `` section of your security configuration
@@ -324,8 +362,8 @@ using the ``simple_preauth`` key:
324
362
authenticator : apikey_authenticator
325
363
326
364
providers :
327
- simple_preauth :
328
- id : your_api_key_user_provider
365
+ api_key_user_provider :
366
+ id : api_key_user_provider
329
367
330
368
.. code-block :: xml
331
369
@@ -346,7 +384,7 @@ using the ``simple_preauth`` key:
346
384
<simple-preauth authenticator =" apikey_authenticator" />
347
385
</firewall >
348
386
349
- <provider name =" simple_preauth " id =" your_api_key_user_provider " />
387
+ <provider name =" api_key_user_provider " id =" api_key_user_provider " />
350
388
</config >
351
389
</srv : container >
352
390
@@ -368,7 +406,7 @@ using the ``simple_preauth`` key:
368
406
),
369
407
'providers' => array(
370
408
'simple_preauth' => array(
371
- 'id' => 'your_api_key_user_provider ',
409
+ 'id' => 'api_key_user_provider ',
372
410
),
373
411
),
374
412
));
@@ -411,8 +449,8 @@ configuration or set it to ``false``:
411
449
authenticator : apikey_authenticator
412
450
413
451
providers :
414
- simple_preauth :
415
- id : your_api_key_user_provider
452
+ api_key_user_provider :
453
+ id : api_key_user_provider
416
454
417
455
.. code-block :: xml
418
456
@@ -433,7 +471,7 @@ configuration or set it to ``false``:
433
471
<simple-preauth authenticator =" apikey_authenticator" />
434
472
</firewall >
435
473
436
- <provider name =" simple_preauth " id =" your_api_key_user_provider " />
474
+ <provider name =" api_key_user_provider " id =" api_key_user_provider " />
437
475
</config >
438
476
</srv : container >
439
477
@@ -453,8 +491,8 @@ configuration or set it to ``false``:
453
491
),
454
492
),
455
493
'providers' => array(
456
- 'simple_preauth ' => array(
457
- 'id' => 'your_api_key_user_provider ',
494
+ 'api_key_user_provider ' => array(
495
+ 'id' => 'api_key_user_provider ',
458
496
),
459
497
),
460
498
));
@@ -464,7 +502,7 @@ case the API key (i.e. ``$token->getCredentials()``) - are not stored in the ses
464
502
for security reasons. To take advantage of the session, update ``ApiKeyAuthenticator ``
465
503
to see if the stored token has a valid User object that can be used::
466
504
467
- // src/Acme/HelloBundle /Security/ApiKeyAuthenticator.php
505
+ // src/AppBundle /Security/ApiKeyAuthenticator.php
468
506
// ...
469
507
470
508
class ApiKeyAuthenticator implements SimplePreAuthenticatorInterface
@@ -518,7 +556,7 @@ stored in the database, then you may want to re-query for a fresh version
518
556
of the user to make sure it's not out-of-date. But regardless of your requirements,
519
557
``refreshUser() `` should now return the User object::
520
558
521
- // src/Acme/HelloBundle /Security/ApiKeyUserProvider.php
559
+ // src/AppBundle /Security/ApiKeyUserProvider.php
522
560
523
561
// ...
524
562
class ApiKeyUserProvider implements UserProviderInterface
@@ -558,7 +596,7 @@ a certain URL (e.g. the redirect URL in OAuth).
558
596
Fortunately, handling this situation is easy: just check to see what the
559
597
current URL is before creating the token in ``createToken() ``::
560
598
561
- // src/Acme/HelloBundle /Security/ApiKeyAuthenticator.php
599
+ // src/AppBundle /Security/ApiKeyAuthenticator.php
562
600
563
601
// ...
564
602
use Symfony\Component\Security\Http\HttpUtils;
@@ -570,7 +608,7 @@ current URL is before creating the token in ``createToken()``::
570
608
571
609
protected $httpUtils;
572
610
573
- public function __construct(ApiKeyUserProviderInterface $userProvider, HttpUtils $httpUtils)
611
+ public function __construct(UserProviderInterface $userProvider, HttpUtils $httpUtils)
574
612
{
575
613
$this->userProvider = $userProvider;
576
614
$this->httpUtils = $httpUtils;
@@ -606,8 +644,8 @@ service:
606
644
# ...
607
645
608
646
apikey_authenticator :
609
- class : Acme\HelloBundle \Security\ApiKeyAuthenticator
610
- arguments : ["@your_api_key_user_provider ", "@security.http_utils"]
647
+ class : AppBundle \Security\ApiKeyAuthenticator
648
+ arguments : ["@api_key_user_provider ", "@security.http_utils"]
611
649
612
650
.. code-block :: xml
613
651
@@ -621,9 +659,9 @@ service:
621
659
<!-- ... -->
622
660
623
661
<service id =" apikey_authenticator"
624
- class =" Acme\HelloBundle \Security\ApiKeyAuthenticator"
662
+ class =" AppBundle \Security\ApiKeyAuthenticator"
625
663
>
626
- <argument type =" service" id =" your_api_key_user_provider " />
664
+ <argument type =" service" id =" api_key_user_provider " />
627
665
<argument type =" service" id =" security.http_utils" />
628
666
</service >
629
667
</services >
@@ -640,7 +678,7 @@ service:
640
678
$container->setDefinition('apikey_authenticator', new Definition(
641
679
'Acme\HelloBundle\Security\ApiKeyAuthenticator',
642
680
array(
643
- new Reference('your_api_key_user_provider '),
681
+ new Reference('api_key_user_provider '),
644
682
new Reference('security.http_utils')
645
683
)
646
684
));
0 commit comments