Skip to content

Improve error handling for invalid access token responses #747

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

Draft
wants to merge 2 commits into
base: 5.x
Choose a base branch
from

Conversation

TobMoeller
Copy link

When an OAuth provider's token endpoint returns an invalid response (non-JSON or missing access_token),
the current code fails with a generic error. This can be confusing when debugging issues,
especially in cases where firewalls or proxy servers intercept the request and return HTML instead
(e.g., Cloudflare access denied pages).

This PR adds an InvalidTokenResponseException that is thrown, if the OAuth provider's response does not contain the required access_token.

@taylorotwell
Copy link
Member

I wonder if the response could be included in the exception? Something that might let developers inspect what is going on.

@taylorotwell taylorotwell marked this pull request as draft June 22, 2025 23:38
@TobMoeller
Copy link
Author

Thanks for the suggestion!

I looked into including the response in the exception, but unfortunately, by the time the exception is thrown, the response has already been processed through json_decode(). This means that any response not containing valid JSON (e.g., an HTML error page or plain text) ends up as null. As a result, we don't have the original response available when raising the exception.

Altering the behavior of the getAccessTokenResponse method or raising the exception earlier would likely result in a breaking change.

If you have other thoughts or an alternative approach, please let me know—I’d be happy to explore it further!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy