Return OAuth authorize errors to redirect_uri per RFC 6749#72
Merged
Conversation
Previously, all errors in the authorize endpoint were returned as raw HTTP error pages directly to the browser. This meant client applications never learned about errors like invalid scope or missing PKCE — the user just saw a plain text error page and the client was left waiting. Now the authorize handler validates in two phases: 1. Client identity and redirect_uri are validated first. If these fail, errors are still shown directly (can't safely redirect to an untrusted URI). 2. All other errors (unsupported response_type, missing PKCE, invalid scope) are redirected back to the client's redirect_uri as query parameters (error, error_description, state) so the client can handle them programmatically. Added validateOAuthClientRedirect for the early client+redirect check, and moved scope validation into the authorize handler so it can use the redirect error path. Closes #58. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The authorize endpoint previously returned all errors as raw HTTP error pages. This broke client integrations — when a scope was invalid or PKCE was missing, the client application never received a callback and the user saw a plain text error.
Per RFC 6749 Section 4.1.2.1, errors should be returned to the client's
redirect_urias query parameters when the redirect_uri has been validated. This PR restructures the authorize handler into two validation phases:?error=<code>&error_description=<msg>&state=<state>so the client can handle them.Changes
HandleOauthAuthorizeto validate client+redirect_uri first, then redirect subsequent errorsvalidateOAuthClientRedirect(validates client+redirect only, without scopes) for the early checkTest plan
Five integration tests written red/green TDD, covering both error categories:
Errors redirected to client (with
error,error_description,statequery params):error=invalid_scopeerror=invalid_requesterror=unsupported_response_typeErrors shown directly (can't trust redirect_uri):
Full regression: All 55+ existing tests pass.
Closes #58.
🤖 Generated with Claude Code