Skip to content

[Cookbook][Security] Hint about createToken can return null #4800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cookbook/security/api_key_authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ value and then a User object is created::

if (!$apiKey) {
throw new BadCredentialsException('No API key found');

// or to just skip api key authentication
// return null;
}

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

2. supportsToken
~~~~~~~~~~~~~~~~
Expand Down