We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Add request object back as parameter to the error handler.
$app->add(new Tuupola\Middleware\HttpBasicAuthentication([ "error" => function ($request, $response, $arguments) { ... } ]));
See tuupola/branca-middleware#13 for reference.
The text was updated successfully, but these errors were encountered:
@tuupola FYI I did a workaround on v3.3.1 to be able to throw a Slim HTTP code.
use Slim\Exception\HttpUnauthorizedException; // 1st middleware to configure basic authentication $app->add(new HttpBasicAuthentication([ "users" => [ "root" => "secret", ], "error" => function ($response) { return $response->withStatus(401); } ])); // 2nd middleware to throw 401 with correct slim exception $app->add(function (Request $request, RequestHandler $handler) { $response = $handler->handle($request); $statusCode = $response->getStatusCode(); if ($statusCode == 401) { throw new HttpUnauthorizedException($request); } return $response; });
any other way to get the request object?
Sorry, something went wrong.
Changing the processError function in HttpBasicAuthentication would give the desired result. Passing the $request through to the use to do whatever.
processError
HttpBasicAuthentication
$request
private function processError(ServerRequestInterface $request, ResponseInterface $response, array $arguments): ResponseInterface { if (is_callable($this->options["error"])) { $handler_response = $this->options["error"]($request, $response, $arguments); if ($handler_response instanceof ResponseInterface) { return $handler_response; } } return $response; }
We can PR this, but that would be breaking for older installations. Don't know if there is a major/minor coming out soon?
As intermit step, adding a option to throw an Exception instead would also give the desired effect.
Yeah cannot break BC. A kludgish workaround would be to include the request object in the second parameter which is an array.
4.x version is planned but since I recently started freelancing paid work comes first atm.
tuupola
No branches or pull requests
Add request object back as parameter to the error handler.
See tuupola/branca-middleware#13 for reference.
The text was updated successfully, but these errors were encountered: