Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Pass request uri as an argument to error handler (see #96)
Browse files Browse the repository at this point in the history
This is a workaround because changing the error handler signature would
break BC. Removing the request in 3.x was an oversight on my part and
it will most likely be put back in 4.x.
  • Loading branch information
tuupola committed Feb 24, 2019
1 parent 33521e3 commit e87879d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/JwtAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
} catch (RuntimeException | DomainException $exception) {
$response = (new ResponseFactory)->createResponse(401);
return $this->processError($response, [
"message" => $exception->getMessage()
"message" => $exception->getMessage(),
"uri" => (string)$request->getUri()
]);
}

Expand Down
29 changes: 29 additions & 0 deletions tests/JwtAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,4 +852,33 @@ public function testShouldHandlePsr7()
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals("Success", $response->getBody());
}

public function testShouldHaveUriInErrorHandlerIssue96()
{
$request = (new ServerRequestFactory)
->createServerRequest("GET", "https://example.com/api/foo?bar=pop");

$dummy = null;

$default = function (ServerRequestInterface $request) {
$response = (new ResponseFactory)->createResponse();
$response->getBody()->write("Success");
return $response;
};

$collection = new MiddlewareCollection([
new JwtAuthentication([
"secret" => "supersecretkeyyoushouldnotcommit",
"error" => function (ResponseInterface $response, $arguments) use (&$dummy) {
$dummy = $arguments["uri"];
}
])
]);

$response = $collection->dispatch($request, $default);

$this->assertEquals(401, $response->getStatusCode());
$this->assertEquals("", $response->getBody());
$this->assertEquals("https://example.com/api/foo?bar=pop", $dummy);
}
}

0 comments on commit e87879d

Please sign in to comment.