Open mattvb91 opened 1 year ago
Provide your model code, please.
Thanks.
How can we add custom claims with for refresh token
Earlier
$newToken = JWTAuth::fromUser($user, [
'exp' => Carbon::now()->addMinutes(config('jwt.ttl'))->timestamp,
'remember' => 0
]);
We need something like
auth()->claims( [
'exp' => Carbon::now()->addMinutes(config('jwt.ttl'))->timestamp,
'remember' => 0
])->refresh()
However the
getJWTCustomClaims()
function is never called when a token is refreshed.
Upfront: it works for me.
Does your User
model have the interface \PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject
implemented, and not just the method added?
I tested this with:
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract, JWTSubject
…
public function getJWTCustomClaims()
{
return [
'foo' => 'bar',
];
}
…
and then did in artisan tinker
:
('api')->tokenById(<my user id>);
and checked it in https://jwt.io/ and the custom claim is there:
Im having the same issue as in this issue over in the old repo: https://github.com/tymondesigns/jwt-auth/issues/891
The short of it is, I have a custom claim in my user model:
However the
getJWTCustomClaims()
function is never called when a token is refreshed.Associated PR from old repo: https://github.com/tymondesigns/jwt-auth/pull/1619
I have tried getting it running quickly by using the above PR as a reference but I am missing the
authenticate()
function in this repo so its not a quick fix unfortunately.