Until today I had the group middleware basic auth being called like this:
->add(new Tuupola\Middleware\HttpBasicAuthentication([
"path" => "/api",
"realm" => "Protected",
"secure" => false,
"authenticator" => new ApiAuthenticator()
]));
But it was calling ApiAuthenticator for every file that came through the slim index (including css and js files) which we want to avoid to reduce unnecessary db calls.
I am attempting to set up the basic auth as an anonymous function to then pass into the group middleware, like this:
$basicAuth = function (Request $request, RequestHandler $handler) use ($app) {
return new Tuupola\Middleware\HttpBasicAuthentication([
"path" => "/api",
"realm" => "Protected",
"secure" => false,
"authenticator" => new ApiAuthenticator()
]);
};
But I am running into issue - I have tried every which combination of request/response/handler that I could think of and completely at a loss.
The error I’m getting is:
TypeError: Return value of class@anonymous::handle() must be an instance of Psr\Http\Message\ResponseInterface, instance of Tuupola\Middleware\HttpBasicAuthentication returned in file /redacted-path/vendor/slim/slim/Slim/MiddlewareDispatcher.php on line 283