'refresh_ttl' => 29030400, // Number of minutes in 1 year (12*4*7*24*60*60)
当您创建令牌时,您可以传递以下内容
$tokenId = base64_encode(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
$issuedAt = Carbon::now()->timestamp;
$notBefore = $issuedAt; //Adding 10 seconds
$expire = $notBefore + 12*4*7*24*60*60; // Adding 6 hours
/*
* Create the token as an array
*/
$data = [
'iat' => $issuedAt, // Issued at: time when the token was generated
'jti' => $tokenId, // Json Token Id: an unique identifier for the token
'iss' => 'https://example.com', // Issuer
'nbf' => $notBefore, // Not before
'exp' => $expire, // Expire
'data' => [ // Data related to the signed user
'userId' => Auth::user()->id, // userid from the users table
]
];
1 回答
没有任何东西可以使令牌永不过期 . 但是,您可以将到期日期延长到非常大的时间 Span ,例如1年 . 这是可能的,但不建议用于安全性 .
为了实现这一点,您需要配置两个部分,即令牌刷新时间和令牌到期 .
所以
config/jwt.php
当您创建令牌时,您可以传递以下内容
现在,您的令牌永远不会在1年之前到期 . 你有最多1年的时间来刷新它 . 当用户下次打开应用程序并验证令牌时,您可以刷新它 . 您可以刷新令牌,如文档_438765中所述 . 我建议也要通过这个laracasts discussion .
另外,我在StackOverflow上发现了这个question,我认为它会有所帮助 .