Skip to content

Commit 08bed5f

Browse files
committed
feature symfony#4128 Finished symfony#3759 (WouterJ)
This PR was merged into the 2.4 branch. Discussion ---------- Finished symfony#3759 Finished the great start by @BourotBenjamin in symfony#3759 Commits ------- 529675a Check for api_key in request 59e4bd4 Update api_key_authentication.rst - POST Method
2 parents 4629d8b + 529675a commit 08bed5f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cookbook/security/api_key_authentication.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@ value and then a User object is created::
4545

4646
public function createToken(Request $request, $providerKey)
4747
{
48-
if (!$request->query->has('apikey')) {
48+
// look for an apikey query parameter
49+
$apiKey = $request->query->get('apikey');
50+
51+
// or if you want to use an "apikey" header, then do something like this:
52+
// $apiKey = $request->headers->get('apikey');
53+
54+
if (!$apiKey) {
4955
throw new BadCredentialsException('No API key found');
5056
}
5157

5258
return new PreAuthenticatedToken(
5359
'anon.',
54-
$request->query->get('apikey'),
60+
$apiKey,
5561
$providerKey
5662
);
5763
}

0 commit comments

Comments
 (0)