From 779c0fcd856fab5f8ab6479fc0fd44231f11e347 Mon Sep 17 00:00:00 2001 From: Benjamin Bourot Date: Fri, 4 Apr 2014 15:22:13 +0200 Subject: [PATCH 1/2] Update api_key_authentication.rst - POST Method --- cookbook/security/api_key_authentication.rst | 26 ++++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/cookbook/security/api_key_authentication.rst b/cookbook/security/api_key_authentication.rst index a5c9f409200..c86d5dd54e9 100644 --- a/cookbook/security/api_key_authentication.rst +++ b/cookbook/security/api_key_authentication.rst @@ -45,15 +45,25 @@ value and then a User object is created:: public function createToken(Request $request, $providerKey) { - if (!$request->query->has('apikey')) { - throw new BadCredentialsException('No API key found'); + if ($request->query->has('apikey')) { + return new PreAuthenticatedToken( + 'anon.', + $request->query->get('apikey'), + $providerKey + ); } - - return new PreAuthenticatedToken( - 'anon.', - $request->query->get('apikey'), - $providerKey - ); + else if($request->request->has('apikey')) + { + return new PreAuthenticatedToken( + 'anon.', + $request->request->get('apikey'), + $providerKey + ); + } + else + { + throw new BadCredentialsException('No API key found'); + } } public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey) From 416ca0f3aad42f6f2df2d6a799310b083e10a24b Mon Sep 17 00:00:00 2001 From: Benjamin Bourot Date: Thu, 12 Jun 2014 18:38:05 +0200 Subject: [PATCH 2/2] Check for api_key in request --- cookbook/security/api_key_authentication.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cookbook/security/api_key_authentication.rst b/cookbook/security/api_key_authentication.rst index c86d5dd54e9..5e25fda59fb 100644 --- a/cookbook/security/api_key_authentication.rst +++ b/cookbook/security/api_key_authentication.rst @@ -52,11 +52,11 @@ value and then a User object is created:: $providerKey ); } - else if($request->request->has('apikey')) + else if($request->headers->has('apikey')) { return new PreAuthenticatedToken( 'anon.', - $request->request->get('apikey'), + $request->headers->get('apikey'), $providerKey ); }