passport
passport copied to clipboard
Cannot Custom Handle `Laravel\Passport\Exceptions\OAuthServerException` in Laravel 11
Passport Version
12.2.0
Laravel Version
11.10.0
PHP Version
8.2.19
Database Driver & Version
MariaDB docker
Description
I tried to custom render Laravel\Passport\Exceptions\OAuthServerException on Laravel 11 as per the documentation. But it doesn't work and just return the default JSON response.
Steps To Reproduce
- Install Laravel 11
- Install Passport 12
- Setup custom render
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!
Hi,
Sure, here is the repository: https://github.com/rulim34/laravel-oauth-exception.git
I wonder what happened here because this should be possible after @matt-allan's PR here: https://github.com/laravel/passport/pull/1066. But maybe something broke with Laravel 11. Would appreciate any help here...
Thank you for reporting this issue!
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
Thank you!
You may check PR #1763
@rulim34 https://github.com/laravel/passport/pull/1763 was merged into https://github.com/laravel/passport/tree/13.x two days ago. Can you close this issue?
Ty!
@hafezdivandari @driesvints sorry to reopen a conversation nearly a year old, I'm a little stuck and I think this may be the issue 🤔
When a route is run in Laravel, it catches the HttpResponseException and immediately returns the contained response - bypassing any exception handling code.
See: https://github.com/laravel/framework/blob/12.x/src/Illuminate/Routing/Route.php#L205-L218
This feels like a regression - in Passport v12, I was able to catch and transform the exception into something matching the format of our stacks errors but I don't think I can do that any more (without a global middleware inspecting each response).
I understand that according to the OAuth RFC this is fine - the defined error messages are part of the standard - and if Passport is aiming to enforce that, then that makes sense. But it seems like the opposite is true?
I'd be very grateful if some light could be shed on this, and happy to think about a PR if y'all feel that allowing the developer to catch and transform these exceptions is something within the scope of Passport.
Equally I could be being a big dumb dumb and missing something obvious around how to catch and transform these exceptions.