-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Token not found in Error Callback instead of notFoundHandler #127
Comments
Confirmed, I do not remember why this is the case. Seems to date back to 2.x branch. Changing this behavior by default would be a BC break, so maybe add a configuration switch to honor 404. Will investigate a bit. |
Now I remember. By default middleware does not have any information about current route. Middleware is also executed for all requests, even those which are made against nonexistent route. As a workaround you could set For example: <?php
require __DIR__ . "/vendor/autoload.php";
$config = [
"settings" => [
"determineRouteBeforeAppMiddleware" => true,
],
];
$app = new Slim\App($config);
$app->add(new Tuupola\Middleware\JwtAuthentication([
"path" => "/",
"secret" => "supersecretkeyyoushouldnotcommittogithub",
"error" => function ($response, $arguments) {
$data["status"] = "error";
$data["message"] = $arguments["message"];
return $response
->withHeader("Content-Type", "application/json")
->getBody()->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
]));
$app->add(function ($request, $response, $next) {
$route = $request->getAttribute("route");
if (empty($route)) {
throw new Slim\Exception\NotFoundException($request, $response);
}
return $next($request, $response);
});
$app->get("/test", function ($request, $response, $arguments) {
print "Brawndo!";
});
$app->run();
|
If call a page that are not maped instead of notFoundHandler is called the error callback of this library.
I.e.: if call https://foo.bar/public/pageitenrionalynotmaped
I receive: {"status": "error", "message": "Token not found"}
I expected: Slim 404 Handler to be called
PHP 7.2.7
Slim 3.1
JWT-Auth: 3.0
The text was updated successfully, but these errors were encountered: