passport icon indicating copy to clipboard operation
passport copied to clipboard

Cannot Custom Handle `Laravel\Passport\Exceptions\OAuthServerException` in Laravel 11

Open rulim34 opened this issue 1 year ago • 5 comments
trafficstars

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. image image image

Steps To Reproduce

  1. Install Laravel 11
  2. Install Passport 12
  3. Setup custom render

rulim34 avatar Jun 22 '24 14:06 rulim34

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!

driesvints avatar Jun 24 '24 18:06 driesvints

Hi,

Sure, here is the repository: https://github.com/rulim34/laravel-oauth-exception.git

rulim34 avatar Jun 24 '24 23:06 rulim34

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...

driesvints avatar Jun 28 '24 09:06 driesvints

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!

github-actions[bot] avatar Jun 28 '24 09:06 github-actions[bot]

You may check PR #1763

hafezdivandari avatar Jun 30 '24 07:06 hafezdivandari

@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?

codespearhead avatar Jul 04 '24 18:07 codespearhead

Ty!

driesvints avatar Jul 04 '24 19:07 driesvints

@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.

jrdnrc avatar Jun 17 '25 07:06 jrdnrc