@@ -56,6 +56,12 @@ value and then a User object is created::
56
56
57
57
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
58
58
{
59
+ if (!$userProvider instanceof ApiKeyUserProvider) {
60
+ throw new \InvalidArgumentException(
61
+ '$userProvider must be an instance of "ApiKeyUserProvider".'
62
+ );
63
+ }
64
+
59
65
$apiKey = $token->getCredentials();
60
66
$username = $userProvider->getUsernameForApiKey($apiKey);
61
67
@@ -293,7 +299,8 @@ First, register it as a service.
293
299
# ...
294
300
295
301
apikey_authenticator :
296
- class : AppBundle\Security\ApiKeyAuthenticator
302
+ class : AppBundle\Security\ApiKeyAuthenticator
303
+ public : false
297
304
298
305
.. code-block :: xml
299
306
@@ -306,7 +313,9 @@ First, register it as a service.
306
313
<services >
307
314
<!-- ... -->
308
315
309
- <service id =" apikey_authenticator" class =" AppBundle\Security\ApiKeyAuthenticator" />
316
+ <service id =" apikey_authenticator"
317
+ class =" AppBundle\Security\ApiKeyAuthenticator"
318
+ public =" false" />
310
319
</services >
311
320
</container >
312
321
@@ -318,9 +327,9 @@ First, register it as a service.
318
327
319
328
// ...
320
329
321
- $container->setDefinition('apikey_authenticator', new Definition(
322
- 'AppBundle\Security\ApiKeyAuthenticator'
323
- ) );
330
+ $definition = new Definition('AppBundle\Security\ApiKeyAuthenticator');
331
+ $definition->setPublic(false);
332
+ $container->setDefinition('apikey_authenticator', $definition );
324
333
325
334
Now, activate it and your custom user provider (see :doc: `/cookbook/security/custom_provider `)
326
335
in the ``firewalls `` section of your security configuration
@@ -496,6 +505,12 @@ to see if the stored token has a valid User object that can be used::
496
505
// ...
497
506
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
498
507
{
508
+ if (!$userProvider instanceof ApiKeyUserProvider) {
509
+ throw new \InvalidArgumentException(
510
+ '$userProvider must be an instance of "ApiKeyUserProvider".'
511
+ );
512
+ }
513
+
499
514
$apiKey = $token->getCredentials();
500
515
$username = $userProvider->getUsernameForApiKey($apiKey);
501
516
@@ -629,6 +644,7 @@ service:
629
644
apikey_authenticator :
630
645
class : AppBundle\Security\ApiKeyAuthenticator
631
646
arguments : ["@security.http_utils"]
647
+ public : false
632
648
633
649
.. code-block :: xml
634
650
@@ -643,6 +659,7 @@ service:
643
659
644
660
<service id =" apikey_authenticator"
645
661
class =" AppBundle\Security\ApiKeyAuthenticator"
662
+ public =" false"
646
663
>
647
664
<argument type =" service" id =" security.http_utils" />
648
665
</service >
@@ -657,11 +674,13 @@ service:
657
674
658
675
// ...
659
676
660
- $container->setDefinition('apikey_authenticator', new Definition(
677
+ $definition = new Definition(
661
678
'AppBundle\Security\ApiKeyAuthenticator',
662
679
array(
663
680
new Reference('security.http_utils')
664
681
)
665
- ));
682
+ );
683
+ $definition->setPublic(false);
684
+ $container->setDefinition('apikey_authenticator', $definition);
666
685
667
686
That's it! Have fun!
0 commit comments