Skip to content
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
10 changes: 8 additions & 2 deletions cookbook/security/api_key_authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ value and then a User object is created::

public function createToken(Request $request, $providerKey)
{
if (!$request->query->has('apikey')) {
// look for an apikey query parameter
$apiKey = $request->query->get('apikey');

// or if you want to use an "apikey" header, then do something like this:
// $apiKey = $request->headers->get('apikey');

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

return new PreAuthenticatedToken(
'anon.',
$request->query->get('apikey'),
$apiKey,
$providerKey
);
}
Expand Down