【发布时间】:2017-01-06 22:42:49
【问题描述】:
我目前正在使用带有 slim-jwt-auth 的 Slim。
我的项目基于 slim-api-skeleton (https://github.com/tuupola/slim-api-skeleton)。 我只需要为创建令牌的用户允许路由。
我已经用下面的代码完成了:
//check if it is the right user
$user = \User::find($args["uid"]);
$token = $request->getHeader('HTTP_AUTHORIZATION');
$token = str_replace("Bearer ", "", $token);
$secret = getenv("JWT_SECRET");
$decoded = JWT::decode($token[0], $secret, array("HS256"));
if ($decoded->sub != $user->email)
{
throw new ForbiddenException("User not allowed to read.");
}
正确吗?还是有更好的方法?
【问题讨论】:
标签: authentication jwt slim