2

我已将https://github.com/tymondesigns/jwt-auth与我的 laravel 应用程序集成。正在生成令牌,但是当添加以下行时,它们无法正确生成并且 console.log() 返回 - 令牌未定义

$customClaims = [
        'sub' => $user->id,
        'iat' => time(),
        'exp' => time() + (2 * 7 * 24 * 60 * 60)
    ];

 $payload = app('tymon.jwt.payload.factory')->make($customClaims);
4

1 回答 1

0

如何根据您喜欢的任何内容创建令牌

use JWTFactory;

$customClaims = ['foo' => 'bar', 'baz' => 'bob'];

$payload = JWTFactory::make($customClaims);

$token = JWTAuth::encode($payload);

您现在可以返回此令牌

您也可以链接索赔..

// add a custom claim with a key of `foo` and a value of ['bar' => 'baz']
$payload = JWTFactory::sub(123)->aud('foo')->foo(['bar' => 'baz'])->make();

$token = JWTAuth::encode($payload);

可以试试这个而不是app('tymon.jwt.payload.factory')->make($customClaims);

于 2015-12-09T07:42:20.267 回答