Skip to content

Commit 572bf3b

Browse files
committed
feature #4800 [Cookbook][Security] Hint about createToken can return null (xelaris)
This PR was merged into the 2.5 branch. Discussion ---------- [Cookbook][Security] Hint about createToken can return null | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.5+ | Fixed tickets | see symfony/symfony#12002 Commits ------- 528aa17 [Cookbook][Security] Hint about createToken can return null
2 parents 4143076 + 528aa17 commit 572bf3b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cookbook/security/api_key_authentication.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ value and then a User object is created::
5252

5353
if (!$apiKey) {
5454
throw new BadCredentialsException('No API key found');
55+
56+
// or to just skip api key authentication
57+
// return null;
5558
}
5659

5760
return new PreAuthenticatedToken(
@@ -103,7 +106,9 @@ is to create a token object that contains all of the information from the
103106
request that you need to authenticate the user (e.g. the ``apikey`` query
104107
parameter). If that information is missing, throwing a
105108
:class:`Symfony\\Component\\Security\\Core\\Exception\\BadCredentialsException`
106-
will cause authentication to fail.
109+
will cause authentication to fail. You might want to return ``null`` instead
110+
to just skip the authentication, so Symfony can fallback to another authentication
111+
method, if any.
107112

108113
2. supportsToken
109114
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)