Access user/passwd from Authenticator within Slim route handler
Closed this issue · 1 comments
witchi commented
I have an own Authenticator (implements AuthenticatorInterface), where I can check the user/password. But I also need both parameters later within the Slim route handler because I have to send the same credentials to a further webservice:
$this->get('/api/things', function(Request $request, Response $response, array $args) {
// FIXME: how I can access user and password from the Authenticator?
$api = new Api($this->externalUri, $user, $passwd);
$things = $api->getThings();
// ....
return $response;
});
witchi commented
Ahh, I can use "before" and inject the user/password into the request attributes, which I can extract with $req->getAttribute() later. And the request will be cloned, so I have to use something like this:
"before" => function ($request, $arguments) {
return $request->withAttribute("user", $arguments["user"])->withAttribute("passwd", $arguments["password"]);
}