corbosman / laravel-passport-claims

Add claims to Laravel Passport JWT Tokens
MIT License
81 stars 12 forks source link

Is there a way to get the private claims from request calls? or a helper? #24

Closed parallels999 closed 1 year ago

parallels999 commented 1 year ago

Look at this, BearerTokenValidator.php#L126-L131,

// Return the request with additional attributes
return $request
    ->withAttribute('oauth_access_token_id', $claims->get('jti'))
    ->withAttribute('oauth_client_id', $this->convertSingleRecordAudToString($claims->get('aud')))
    ->withAttribute('oauth_user_id', $claims->get('sub'))
    ->withAttribute('oauth_scopes', $claims->get('scopes'));

For example, I has company_id on private claims, and the middleware check works correctly, but I want to use the id to make queries with results only from that company, It would be useful to have a static property where the token is stored, and a helper, so we can get the claims from anywhere Example:

///
$query->where('company_id', token_private_claim('company_id'))
///
corbosman commented 1 year ago

This package is really not meant to be more than it currently is. It's pretty easy to make a helper that does what you need. Just check how I parse the token in the middleware and add that to a helper.

parallels999 commented 1 year ago

check how I parse the token in the middleware and add that to a helper

Yes, i already did that, but since that code is already there, it could be made available

Would any PR be accepted for that?