【发布时间】:2017-06-05 11:37:49
【问题描述】:
根据上面的问题,我有 api/user 包含 get、post、put 和 delete 方法。是否可以在特定方法上使用passthrough?
例如,公共方法只有get,其余的需要令牌才能使用该方法?
感谢您的回答。
$app->add(new \Slim\Middleware\JwtAuthentication([
"path" => ["/api", "/admin"],
"passthrough" => ["/api/login", "/admin/ping", "/api/user"],
"algorithm" => "HS256",
"secret" => getenv("JWT_SECRET"),
"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));
}]));
【问题讨论】: