-
Notifications
You must be signed in to change notification settings - Fork 784
[13.x] Configure the user provider for PAT #1768
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
[13.x] Configure the user provider for PAT #1768
Conversation
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
@hafezdivandari forgive me but I don't really understand why all of this is necessary. Passport should only issue tokens for one client? Why offer support for different guards? Could you give some practical use cases? |
@driesvints thank you for asking. We already support different guards and user providers not only on Passport but on the entire Laravel auth system. On Passport, the Sanctum has the same ability, that you can use What this PR does is that it fixes a bug on Passport PAT when using customized user provider. But the support for different guards is not about Passport or something that this PR offer. |
Thanks @hafezdivandari. I think I might not fully understand yet. For me, there should only be the current |
@driesvints let me explain that, assume that you have different guards / user providers like this one. Then you issue token for each one: $user->createToken('user token'); // uses default client to issue token
$businessUser->createToken('business user token'); // also uses the default client to issue token! both these tokens have the same |
@hafezdivandari thanks for that. I fully understand now. I think the PR is okay in this case but just got one remark: So for each user provider you need to run Shouldn't the config then look like: 'personal_access_client' => [
'users' => [
'id' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_ID'),
'secret' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET'),
],
'customers' => [
'id' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_CUSTOMER_ID'),
'secret' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_CUSTOMER_SECRET'),
],
], |
@driesvints for backward compatibility, it first look for the specified provider credentials, if not found it fallbacks to |
|
||
if (! $config) { | ||
if (! $client || ($client->provider && $client->provider !== $provider)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be the same as the check on TokenGuard
:
passport/src/Guards/TokenGuard.php
Lines 186 to 188 in 8ea1dd4
if (! $client || | |
($client->provider && | |
$client->provider !== $this->provider->getProviderName())) { |
Thanks for your work @hafezdivandari |
We have documented how to add a guard with 'passport' as driver and set its 'provider'. So it's common practice to have several guards and providers. This PR makes PAT factory respect the guard provider when issuing personal access tokens.
Changes
Add feature tests.
Require
user_id
onPersonalAccessGrant
.Add
getProvider()
method toHasApiTokens
to get the user provider name.Make
PersonalAccessTokenFactory
to check forconfig('passport.personal_access_client.{provider}')
before getting default PAT credentials fromconfig('passport.personal_access_client')
. For example, havingcustomers
auth provider: