I followed the instructions to save token in container with callback function (https://github.com/tuupola/slim-jwt-auth):
$app = new \Slim\App();
$container = $app->getContainer();
$container["jwt"] = function ($container) {
return new StdClass;
};
$app->add(new \Slim\Middleware\JwtAuthentication([
"path" => ["/"],
"passthrough" => ["/version", "/auth"],
"secret" => "mysecret",
"callback" => function ($request, $response, $arguments) use ($container) {
$container["jwt"] = $arguments["decoded"];
},
"error" => function ($request, $response, $arguments) {
$data["status"] = "error";
$data["message"] = $arguments["message"];
return $response
->withHeader("Content-Type", "application/json")
->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
]));
No data is returned in response, it seems $this->jwt is empty.
$app->get("/user", 'getUsers');
function getUsers($req, $res, $args) {
$decode = $this->jwt;
print_r($decode);
}