讨论数量:
以获取token流程为例
//$token = auth('api')->login($user);
//在JWT类中如下使用
namespace Tymon\JWTAuth;
......
class JWT
{
protected function getClaimsArray(JWTSubject $subject) //$subject 其实就是$user
{
return array_merge(
$this->getClaimsForSubject($subject),
$subject->getJWTCustomClaims(), // custom claims from JWTSubject method
$this->customClaims // custom claims from inline setter
);
}
protected function getClaimsForSubject(JWTSubject $subject)
{
return array_merge([
//这里就是生成token中sub对应的值,一般选用id ,即你模型中这个getJwtIdentifier()中返回$this->getKey(); 同样解析的时候也是获取这里
'sub' => $subject->getJWTIdentifier(),
], $this->lockSubject ? ['prv' => $this->hashSubjectModel($subject)] : []);
}
推荐文章: