Return RFC 6750 compliant JSON error responses from auth middleware#4057
Merged
Return RFC 6750 compliant JSON error responses from auth middleware#4057
Conversation
Made-with: Cursor
ae44c8f to
f32a41f
Compare
jerm-dro
previously approved these changes
Mar 9, 2026
jerm-dro
previously approved these changes
Mar 9, 2026
reyortiz3
reviewed
Mar 9, 2026
reyortiz3
reviewed
Mar 9, 2026
reyortiz3
reviewed
Mar 9, 2026
reyortiz3
reviewed
Mar 9, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4057 +/- ##
=======================================
Coverage 68.63% 68.63%
=======================================
Files 446 446
Lines 45424 45435 +11
=======================================
+ Hits 31175 31183 +8
Misses 11840 11840
- Partials 2409 2412 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
reyortiz3
approved these changes
Mar 9, 2026
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 token validator middleware was returning plain text error bodies via
http.Error()on401responses. RFC 6750-compliant OAuth clients (e.g. Claude Code) expect a JSON error body and fail to parse the plain text response with:This PR adds a
writeOAuthErrorhelper that returns a proper RFC 6750 Section 3 JSON error response withContent-Type: application/jsonand a body of the form:{ "error": "invalid_request", "error_description": "authorization header required" }All three error paths in
TokenValidator.Middlewareare updated:invalid_requestinvalid_tokeninvalid_tokenFixes #4055
Type of change
Test plan
TestMiddleware_RFC6750JSONErrorResponsecovering missing Authorization header, wrong scheme, and malformed bearer token — verifyingContent-Type: application/json, valid JSON body, correcterrorcode, and non-emptyerror_descriptionpkg/auth/...test suite passesGenerated with Claude Code