From 6f5ec383429fd3097d501a5d236a109c0ff4865e Mon Sep 17 00:00:00 2001 From: Mika Tuupola Date: Fri, 1 Feb 2019 19:25:32 +0200 Subject: [PATCH] Add request object back to error handler See also https://github.com/tuupola/slim-jwt-auth/issues/96 --- src/BrancaAuthentication.php | 11 +++++++---- tests/TestErrorHandler.php | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/BrancaAuthentication.php b/src/BrancaAuthentication.php index 07ebbb1..e5ff491 100644 --- a/src/BrancaAuthentication.php +++ b/src/BrancaAuthentication.php @@ -141,9 +141,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $decoded = $this->decodeToken($token); } catch (RuntimeException $exception) { $response = (new ResponseFactory)->createResponse(401); - return $this->processError($response, [ - "message" => $exception->getMessage() - ]); + return $this->processError( + $request, + $response, + ["message" => $exception->getMessage()] + ); } /* Add decoded token to request as attribute when requested. */ @@ -214,11 +216,12 @@ private function processAfter( * Call the error handler if it exists */ private function processError( + ServerRequestInterface $request, ResponseInterface $response, array $arguments ): ResponseInterface { if (is_callable($this->options["error"])) { - $handlerResponse = $this->options["error"]($response, $arguments); + $handlerResponse = $this->options["error"]($request, $response, $arguments); if ($handlerResponse instanceof ResponseInterface) { return $handlerResponse; } diff --git a/tests/TestErrorHandler.php b/tests/TestErrorHandler.php index ee037a4..6ca39f9 100644 --- a/tests/TestErrorHandler.php +++ b/tests/TestErrorHandler.php @@ -40,8 +40,8 @@ class TestErrorHandler { - //ServerRequestInterface $request, public function __invoke( + ServerRequestInterface $request, ResponseInterface $response, array $arguments ) { @@ -49,8 +49,8 @@ public function __invoke( return $response; } - //ServerRequestInterface $request, public static function error( + ServerRequestInterface $request, ResponseInterface $response, array $arguments ) {