-
Notifications
You must be signed in to change notification settings - Fork 296
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
[2.x] Added Multiple Provider Support #149
Conversation
This PR seems to break our usage of "auth:sanctum" as a Guard for GraphQL calls (using Lighthouse). Tried to pinpoint what's causing it, but haven't been able to find out. We've downgraded to 2.3.3 and all is fine now. |
@KoenLav How ? |
Just noticed the same problem as KoenLav. Confirmed by downgrading from 2.4.0 to 2.3.3. For unknown reason axios calls fail when auth:sanctum route guard is added.
|
This is exactly the thing I was looking for. I'd just wanted to add that in config/sanctum.php you should set:
Otherwise in your session based SPA you could get response code 200 for the resources where you expect it to be 401. |
@ivand88 Or instead of using web guard, you can define a custom guard with session driver. |
It's not that simple. Please look at the source for the sanctum, and the whole discussion within this PR (Especially issue which mentions this PR #232). |
I'd be glad if you explain more. |
Based on this, I was expecting to use something like
But that doesn't seem to work, because when I want to login with |
|
I was under the impression that sanctum could work with guards and session cookies, as that's stated in the docs, however, it seems that this is only possible for a single guard. As we have 2 portals in the same app, we need multiple guards. As part of our application is already using Laravel Passport, I switched to using API tokens with it. Thanks for the response. |
@dietergeerts It's actually possible with laravel you just need to call For the routing it is Route::group(['middleware' => ['auth:admin-api,admin']], function () {
//
}); |
So far Laravel Sanctum has not supported any multiple providers based auth guard. So I have added a function called
hasValidProvider
which accepts thetokenable
model and then it matches if thetokenable_type
model is aninstanceof
the provider type. if no provider defined it always returnstrue
.You need to add guards like this: