jwt-auth ttl 过期设置为 null 的坑
jwt-auth 配置文件
如果ttl 的过期时间设置为null的话
请将下面的required_claims 数组中的exp 这个过期必要字段注释掉。
因为在检查比对的时候 如果ttl 设置为null 程序会把exp字段从default claim选项中删除,导致token永远产生不出来
但是会报一个异常 ,如果有写异常检查的话很容易发现,如果没有下异常处理,那只能像我一样,把代码翻一遍了。
定位文件位置 项目/vendor/tymom/jwt-auth/src/Factory.php Line 143
异常提示信息:JWT payload does not contain the required claims。
/**
* Build the default claims.
*
* @return $this
*/
protected function buildClaims()
{
// remove the exp claim if it exists and the ttl is null
if ($this->claimFactory->getTTL() === null && $key = array_search('exp', $this->defaultClaims)) {
unset($this->defaultClaims[$key]);
}
// add the default claims
foreach ($this->defaultClaims as $claim) {
$this->addClaim($claim, $this->claimFactory->make($claim));
}
// add custom claims on top, allowing them to overwrite defaults
return $this->addClaims($this->getCustomClaims());
}
所以为了测试的话,尽量设置个大点的ttl过期时间,设置null的话也无可厚非,但是有些坑还是会踩的。
本作品采用《CC 协议》,转载必须注明作者和本文链接
有时新部署项目,忘记配置TTL,,结果就是,一登录,就提示token已过期,,,