【发布时间】:2019-05-22 23:59:25
【问题描述】:
- “laravel/framework”:“5.7.*”
- "tymon/jwt-auth": "dev-develop"
我正在尝试使用添加的自定义声明创建 JWT 令牌,没有身份验证(这意味着我不希望从凭据创建令牌。)这是为了创建令牌不需要登录,例如忘记/重置密码等。
- 使用 Tymon/JWTAuth (https://github.com/tymondesigns/jwt-auth) 由于最新的 Laravel 存在问题,建议加载最新的开发 ( 1.0.x-dev )。 我尝试了以下代码但无济于事:
class OTL extends Model implements JWTSubjectuse JWTAuth;use Tymon\JWTAuth\Contracts\JWTSubject;use Tymon\JWTAuth\Facades\JWTFactory;
public static function getJwtToken($customerId, $action, $token){
$customClaims = ['action' => $action, 'customer-id' => $customerId, 'token' => $token];
$factory = JWTFactory::customClaims($customClaims);
$payload = $factory->make();
$token = JWTAuth::encode($payload);
return $token;
我收到一个错误:JWT payload does not contain the required claims。
我希望收到包含上述有效负载的令牌。
【问题讨论】:
-
您好,也许是 jwt-auth 包不允许您在没有身份验证声明的情况下使用 jwt 令牌?也许你应该尝试在这里使用原生 jwt 库 jwt.io/#libraries-io ?您也可以尝试覆盖生成令牌的方法