From 189fecf6fb2c9ed4c55c8d93dcc4d092a069fa95 Mon Sep 17 00:00:00 2001 From: Andrey Bolonin Date: Wed, 19 Oct 2016 10:45:25 +0300 Subject: [PATCH 1/4] Update guard_authentication.rst --- security/guard_authentication.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/security/guard_authentication.rst b/security/guard_authentication.rst index 847479c371f..0407637238f 100644 --- a/security/guard_authentication.rst +++ b/security/guard_authentication.rst @@ -175,9 +175,9 @@ This requires you to implement six methods:: } // What you return here will be passed to getUser() as $credentials - return array( + return [ 'token' => $token, - ); + ]; } public function getUser($credentials, UserProviderInterface $userProvider) @@ -206,14 +206,14 @@ This requires you to implement six methods:: public function onAuthenticationFailure(Request $request, AuthenticationException $exception) { - $data = array( + $data = [ 'message' => strtr($exception->getMessageKey(), $exception->getMessageData()) // or to translate this message // $this->translator->trans($exception->getMessageKey(), $exception->getMessageData()) - ); + ]; - return new JsonResponse($data, 403); + return new JsonResponse($data, Response::HTTP_FORBIDDEN); } /** @@ -221,12 +221,12 @@ This requires you to implement six methods:: */ public function start(Request $request, AuthenticationException $authException = null) { - $data = array( + $data = [ // you might translate this message 'message' => 'Authentication Required' - ); + ]; - return new JsonResponse($data, 401); + return new JsonResponse($data, Response::HTTP_UNAUTHORIZED); } public function supportsRememberMe() From 33b80b128f47689cb6baefbc35659d4a37701928 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 21 Nov 2016 11:22:48 +0100 Subject: [PATCH 2/4] Reverted the short array notation --- security/guard_authentication.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/security/guard_authentication.rst b/security/guard_authentication.rst index 0407637238f..2d0845ccf10 100644 --- a/security/guard_authentication.rst +++ b/security/guard_authentication.rst @@ -55,7 +55,7 @@ property they use to access their account via the API:: public function getRoles() { - return ['ROLE_USER']; + return array('ROLE_USER'); } public function getPassword() @@ -175,14 +175,14 @@ This requires you to implement six methods:: } // What you return here will be passed to getUser() as $credentials - return [ + return array( 'token' => $token, - ]; + ); } public function getUser($credentials, UserProviderInterface $userProvider) { - $apiKey = $credentials['token']; + $apiKey = $credentials'token']; // if null, authentication will fail // if a User object, checkCredentials() is called @@ -206,12 +206,12 @@ This requires you to implement six methods:: public function onAuthenticationFailure(Request $request, AuthenticationException $exception) { - $data = [ + $data = array( 'message' => strtr($exception->getMessageKey(), $exception->getMessageData()) // or to translate this message // $this->translator->trans($exception->getMessageKey(), $exception->getMessageData()) - ]; + ); return new JsonResponse($data, Response::HTTP_FORBIDDEN); } @@ -221,10 +221,10 @@ This requires you to implement six methods:: */ public function start(Request $request, AuthenticationException $authException = null) { - $data = [ + $data = array( // you might translate this message 'message' => 'Authentication Required' - ]; + ); return new JsonResponse($data, Response::HTTP_UNAUTHORIZED); } From c0fe398022c55cf4591d7562ea3c7b2854feeee3 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 21 Nov 2016 11:25:00 +0100 Subject: [PATCH 3/4] Added the missing "use" import for the Response class --- security/guard_authentication.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/security/guard_authentication.rst b/security/guard_authentication.rst index 2d0845ccf10..f4ecee442f8 100644 --- a/security/guard_authentication.rst +++ b/security/guard_authentication.rst @@ -155,6 +155,7 @@ This requires you to implement six methods:: use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; + use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Guard\AbstractGuardAuthenticator; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; From bf2992324cd235181a4017652a9edac12316560b Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 21 Nov 2016 11:26:09 +0100 Subject: [PATCH 4/4] Reverted a change made by mistake --- security/guard_authentication.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/guard_authentication.rst b/security/guard_authentication.rst index f4ecee442f8..65ae5fb61a2 100644 --- a/security/guard_authentication.rst +++ b/security/guard_authentication.rst @@ -183,7 +183,7 @@ This requires you to implement six methods:: public function getUser($credentials, UserProviderInterface $userProvider) { - $apiKey = $credentials'token']; + $apiKey = $credentials['token']; // if null, authentication will fail // if a User object, checkCredentials() is called