Closed rickgoemans closed 1 year ago
Heya, thanks for reporting.
We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
laravel new bug-report --github="--public"
Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.
Thanks!
The repository can be found here:
https://github.com/rickgoemans/bug-report
P.S. This was set up and tested using: PHP: 8.2.0 Laravel: 9.47.0 Passport: 11.5.0 Database: MySQL 8.0.31
.env.example
to .env
(adjust to your needs).composer install
sail up -d
sail artisan migrate:fresh --seed
admin@admin.com
and admin
.@rickgoemans there's many unrelated changes in that commit to the issue. Can you please create one separate commit for the passport install scaffold and one separate commit with the bare minimum of changes to reproduce the issue? Meaning no docblocks or styling changes etc
@driesvints I've made a new repo: https://github.com/rickgoemans/laravel-passport-bug-report
The commit for the Laravel Passport scaffold: https://github.com/rickgoemans/laravel-passport-bug-report/commit/b8fe366b358702359cffe96d1cc3641b1c35ce59
The commit for the minimum changes to reproduce: https://github.com/rickgoemans/laravel-passport-bug-report/commit/af1cbdd7cca8b75a194229b8b3692531f35482e6
.env.example
to .env
(and adjust to your needs)composer install
sail up -d
sail artisan migrate fresh --seed
(might have to run sail artisan passport:install
to setup encryption keys)test@example.com
and password
). Once logged, it, it show a basic page with a logout button.I've tried by defining the provider
to outsmart_users
in the PassportSeeder
but the issue still persist.
Thanks for the thorough info @rickgoemans.
I'm confused here. Your example nowhere shows the Authorization Code Grant with PKCE code and you're using views etc. Pasport is meant to be used with API's, not views (unless you're using PAT but we instead recommend Sanctum for that). This doesn't seem like a real-world example to me.
Can you please try a support channel instead?
The reason I supplied a simple view for the login is that you can login and authorize the request.
We are using a separate Nuxt SPA application with the @nuxtjs/auth-next
module for authorization.
If you want me to setup a basic repo for that, I will, but I suppose that's not the focus here.
In the real project we will redirect from the frontend (http://localhost:3000 on local development) to Passport's authorize url (http://localhost/oauth/authorize?client_id=1&redirect_uri=http://localhost:3000/auth/callback&response_type=code&scope=*&state=drq9a1mdykonu2uplhnjgit6wqelwocx0jfq3uq5&code_challenge=MsUnJvDKMIOox2WOvOjFCeFLvHb4DwpQTqgicT7szoE&code_challenge_method=S256).
I really hope you could look into it because I don't think I can give any more information related to the (Laravel) backend. Plus the exception that is thrown is regardless of what frontend framework you throw at it.
As you can see the $this->guard->user() resolves correctly but the $request->user() does not. Also the current driver states web instead of web_new.
@rickgoemans what about $request->user(config('passport.guard'))
also resolves correctly? check this PR #1613
Description:
While using a different guard than the default version in
config/auth.php
, the request cannot resolve the user during authorization.Steps To Reproduce:
We are using multiple guards and try to achieve a Authorization Code Grant with PKCE.
Here's out auth config (simplified):
We have
web
as default but we useweb_new
for the Laravel Passport. So we defined theguard
inconfig/passport.php
to beweb_new
, but we keep getting an error on theLaravel\Passport\Http\Controllers\AuthorizationController
on line 102 which states:Which is caused by line 97:
Because that ends up
null
.Therefore I've tried to add some the following logging:
As you can see the
$this->guard->user()
resolves correctly but the$request->user()
does not. Also the current driver statesweb
instead ofweb_new
.This is our (simplified) controller processing the login request (after being redirected to the view page with a form due to an unauthenticated exception) does this:
Am I misconfiguring something or is there something broken related to multiple guards?