You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since #161 has been locked we are no longer able to discuss the issue. Before I submit a PR I want to make sure we have a common ground on what the expected behavior is for multi-provider support in Passport. More specifically, should the provider be defined at the oauth client level? This would limit that client id/secret pair to always return from a specific provider. If the gate requested another provider than what the client has defined it would return a 401.
This is the functionality I have built into my current project and I would be more than willing to issue a PR for it but I want to make sure that is what everyone is expecting.
EDIT: I should note, that if no provider is set on the oauth client then it will follow the same logic as what is in place now, so it should be backward compatible outside of the migration.
Reacted by (Rew) Andrew McLagan, Rayron Victor, Ankur K, newvertex, samattar, Mr. Slump, Daniyal Javani, Piotr K., Cyril de Wit, n123456789k and 11 more
Reacted by (Rew) Andrew McLagan
Reacted by (Rew) Andrew McLagan and Socheat
Reacted by (Rew) Andrew McLagan, Cyril de Wit, Mohammad Ali Amini, Socheat and Malte Buttjer
Reacted by (Rew) Andrew McLagan, Jorge Iñiguez, Socheat and eloiletagant
I agree that this issue might be a good place to restart the discussion on how to implement this. I currently don't have time myself to look into this but feel free to provide thoughts here.
Warning: I'll be removing all comments which aren't related to looking for an actual implementation to prevent this issue from de-railing like the other one. Please only discuss the possible implementation for this.
Reacted by Nabarun Gogoi, (Rew) Andrew McLagan, Cyril de Wit and vladozilka
I think to get this started we should first determine if the multi-auth implementation should be enforced or not. Meaning, should the gate simply return the user against its own provider or should the client have a provider that enforces the user must come from a specific provider?
Or to make it more dynamic, the provider can be supplied in the request and the guard check can be made against that request parameter to make it compatible with as many models as required
Personally, I think each oauth_client should be limited to 1 provider but I can see how this may be limiting in some use cases. If we open it up to multiple providers per client then the developer will always be responsible for returning the correct user against any of the allowed providers.
Reacted by Guruprasad Rugi, Nabarun Gogoi and (Rew) Andrew McLagan
Personally, I think each oauth_client should be limited to 1 provider but I can see how this may be limiting in some use cases. If we open it up to multiple providers per client then the developer will always be responsible for returning the correct user against any of the allowed providers.
But isn't that the point of having multi-auth, to have the flexibility of choosing a provider but at the same time, using fallbacks for default behavior, like using the User model as is the case now.
Personally, I too think that each oauth_client should have one provider but its better to have the implementation for multiple providers as it is might offer more functionality.
We should probably gather more opinions on this and implement the consensus then.
I was hoping for some more feedback as to what way would make the most sense for everyone. I can put a PR together later this week with my implementation and see how that goes.
I think the provider should be based on the routes... therefore different routes will have different providers.
Suppose there is an admin model. We can set different routes in the boot() method of AuthServiceProvider like so...
Here I am assigning a middleware(which needs to be implemented accordingly) to the the routes as to tell passport to use the admin guard which decides the provider to be used.
What do you folks think? @billriess@driesvints
I think that if you're using Passport then it should be relatively safe to assume that you're not a beginner developer, and for that reason it should be as flexible as possible even if that means that a little work is required of the developer.
I think it makes sense to have separate endpoints per your suggestion @nikugogoi for the various models so long as there is flexibility in the way those models are authenticated -- some models may not use email / password for example, we may use uuid/id and secret key or some such authentication.
As long as the implementation allows us to attach multiple guards to a single api endpoint, e.g. if i wanted either users, or admins, or whoever to be able to access the resource.
Route::group(['middleware' => ['auth:api', 'auth:admin']], function () {
dd(Auth::guard('admin')->check());
});
returns true even if I pass the user token. I've tried to create a new client for Admin model with the artisan command: php artisan passport:client --provider=admins
but it also seems to not work as expected. It created a new client but provider field is null.
You set the provider when you create the oauth_client, it doesn't set the provider afterward. The purpose of this is to make sure only 1 provider can use the oauth_client. If you don't need this functionality you can leave it null. This is for password grants.
That doesn't work for me. I'm logged in as user but Auth::guard() tells me that I'm an admin...maybe some docs on this. How can we use this to check which guard is logged in on same route handler?
Reacted by Rahul Dey, Sullivan Rander and jcsoriano
Step 3: i have updated my models file to implement HasApiTokens Trait and extends Model with Authenticatable class intead of Model
// App\User.php
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens;
}
// App\Contractor.php
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;
class Contractor extends Authenticatable
{
use HasApiTokens;
}
// App\Crew.php
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens;
}
Step 4: in my ApiController which i used for users authentication and his/her authenticated routes
Activity
[-]Passport Multi Provider[/-][+]Passport Multi-Auth (Implementation)[/+]driesvints commentedon Mar 5, 2019
I agree that this issue might be a good place to restart the discussion on how to implement this. I currently don't have time myself to look into this but feel free to provide thoughts here.
Warning: I'll be removing all comments which aren't related to looking for an actual implementation to prevent this issue from de-railing like the other one. Please only discuss the possible implementation for this.
billriess commentedon Mar 6, 2019
I think to get this started we should first determine if the multi-auth implementation should be enforced or not. Meaning, should the gate simply return the user against its own provider or should the client have a provider that enforces the user must come from a specific provider?
pramanikriju commentedon Mar 11, 2019
Or to make it more dynamic, the provider can be supplied in the request and the guard check can be made against that request parameter to make it compatible with as many models as required
afilippov1985 commentedon Mar 12, 2019
Hello everyone.
Take a look at my proposal #987
billriess commentedon Mar 14, 2019
Personally, I think each
oauth_clientshould be limited to 1 provider but I can see how this may be limiting in some use cases. If we open it up to multiple providers per client then the developer will always be responsible for returning the correct user against any of the allowed providers.pramanikriju commentedon Mar 14, 2019
But isn't that the point of having multi-auth, to have the flexibility of choosing a provider but at the same time, using fallbacks for default behavior, like using the User model as is the case now.
Personally, I too think that each
oauth_clientshould have one provider but its better to have the implementation for multiple providers as it is might offer more functionality.We should probably gather more opinions on this and implement the consensus then.
driesvints commentedon Mar 18, 2019
Please remember to keep this discussion on topic.
pramanikriju commentedon Mar 24, 2019
@billriess When can we expect a PR with the functionality that you have implemented?
billriess commentedon Mar 24, 2019
I was hoping for some more feedback as to what way would make the most sense for everyone. I can put a PR together later this week with my implementation and see how that goes.
nikugogoi commentedon Mar 28, 2019
I think the provider should be based on the routes... therefore different routes will have different providers.
Suppose there is an admin model. We can set different routes in the boot() method of
AuthServiceProviderlike so...Here I am assigning a middleware(which needs to be implemented accordingly) to the the routes as to tell passport to use the
adminguard which decides the provider to be used.What do you folks think? @billriess @driesvints
zagreusinoz commentedon Mar 30, 2019
I think that if you're using Passport then it should be relatively safe to assume that you're not a beginner developer, and for that reason it should be as flexible as possible even if that means that a little work is required of the developer.
I think it makes sense to have separate endpoints per your suggestion @nikugogoi for the various models so long as there is flexibility in the way those models are authenticated -- some models may not use email / password for example, we may use uuid/id and secret key or some such authentication.
As long as the implementation allows us to attach multiple guards to a single api endpoint, e.g. if i wanted either users, or admins, or whoever to be able to access the resource.
27 remaining items
driesvints commentedon Apr 30, 2020
You all can thank @billriess for getting this in.
lucadegasperi commentedon Apr 30, 2020
Thanks @billriess amazing job!
hamedov93 commentedon May 2, 2020
Great work @billriess
RahulDey12 commentedon May 18, 2020
So What should I actually do then.
Is it only supported for password grant token ?
because provider is
nullfor personal access tokenwdarins commentedon May 18, 2020
Can you please also update the docs? I've created 2 guards:
with the following providers:
now when I try to use it:
returns true even if I pass the user token. I've tried to create a new client for Admin model with the artisan command:
php artisan passport:client --provider=adminsbut it also seems to not work as expected. It created a new client but provider field is null.
driesvints commentedon May 18, 2020
RahulDey12 commentedon May 18, 2020
@driesvints is it only creates password grant token. cuz in the personal access token provider is still
nullbillriess commentedon May 18, 2020
You set the provider when you create the oauth_client, it doesn't set the provider afterward. The purpose of this is to make sure only 1 provider can use the oauth_client. If you don't need this functionality you can leave it null. This is for password grants.
RahulDey12 commentedon May 18, 2020
@billriess is it possible to have this functionality for personal access token
wdarins commentedon May 18, 2020
That doesn't work for me. I'm logged in as user but Auth::guard() tells me that I'm an admin...maybe some docs on this. How can we use this to check which guard is logged in on same route handler?
billriess commentedon May 18, 2020
This is for password grants not personal access tokens.
wdarins commentedon May 19, 2020
@billriess what's the use case for this?
RahulDey12 commentedon May 24, 2020
@billriess will it work with
CreateFreshApiTokenmiddlewaredonakhseputa commentedon Mar 28, 2022
how to return
access_tokenandrefresh_token??