-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Add the ability to set custom claims #9
Comments
You can actually already do this @ludo237 using custom generation. This is how tokens are generated without a custom generator, so you could just provide your own generation and add your own custom claims. |
Oh I saw the README I have two final questions: Should I put my |
@ludo237 You do not need a custom guard. If you put this in a service provider, doesn't matter which one as long as it's in the Auth::guard('api')->setTokenGenerator(function (\Illuminate\Contracts\Auth\Authenticatable $user, \Sprocketbox\JWT\JWTGuard $guard) {
$time = Carbon::now();
$expiry = new CarbonInterval($this->config['ttl']);
return (new Builder)
->issuedBy(config('app.url'))
->permittedFor(config('app.url'))
->identifiedBy(Uuid::uuid4()->toString())
->issuedAt($time->timestamp)
->expiresAt($time->copy()->add($expiry)->timestamp)
->relatedTo($user->getAuthIdentifier());
}); The generator must return an instance of |
oh interesting, I need to experiment a bit because I'd like to pass a custom parameter for the claim |
@ludo237 You have given me an idea though. |
Glad I did. if I can help with the code don't esitate ask me. |
It would be nice to add custom claims before receiving the token from the Auth guard. What do you think?
The text was updated successfully, but these errors were encountered: