laravel / passport

Laravel Passport provides OAuth2 server support to Laravel.
https://laravel.com/docs/passport
MIT License
3.29k stars 780 forks source link

Issue when use multi auth #1604

Closed michaelnabil230 closed 1 year ago

michaelnabil230 commented 1 year ago

Description:

I have a problem when I create multiple authentications.

When I visit one of the links that have the user's authority and I make sure if this user is an admin or user using auth()->check() gives the result that the admin is true, although the token used in the request is a user's token, not an admin

I followed the instructions in the package's docs but to no avail.

I was done creating a unit test to try this point only.

Steps To Reproduce:

https://github.com/michaelnabil230/laravel-passport-issue

michaelnabil230 commented 1 year ago

Can be seen in the unit test with the link: https://github.com/michaelnabil230/laravel-passport-issue/blob/master/tests/Feature/HomeTest.php

Can also see the result of the unit test with the link: https://github.com/michaelnabil230/laravel-passport-issue/actions/runs/3660881096

driesvints commented 1 year ago

Multi auth isn't meant to be used with personal access tokens. It's meant to be used with the OAuth grants like the passport grant. Also, you're using the passport:install command at the beginning of your tests but that won't install the password grant for the admins provider. Please see the docs about that here: https://laravel.com/docs/9.x/passport#customizing-the-user-provider