fix: handle multiple OAuth callback formats in browser auth - #19
Merged
Conversation
Extract parseCallbackCode() to handle four input formats users may paste: 1. Full callback URL with query parameters 2. Query string (code=...&state=...) 3. Hash-separated code#state (existing behavior, preserved) 4. Plain authorization code Previously only the hash-separated format and plain code were handled. Users who copy the full redirect URL from their browser address bar would get a failed token exchange. Includes test suite for all supported formats.
- Strip hash fragment before URLSearchParams to fix code=abc#state interaction - Throw on OAuth error responses and missing code param instead of silent fallthrough - Use !== null instead of truthiness for empty code handling - Add regression tests for all fixed edge cases
|
🎉 This PR is included in version 1.4.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
Based on PR #18 by @Steffen025 with review fixes applied.
parseCallbackCode()helper for four OAuth callback input formatscode=abc#statewas not stripped correctly)!== nullinstead of truthiness for empty code handlingOriginal problem
Users copying the full redirect URL from the browser address bar during "Claude Pro/Max (browser)" auth caused silent token exchange failures.
Changes from original PR
#fragment beforeURLSearchParamsparsing (fixescode=abc#state=xyzregression)?error=responsescodeparameter (instead of returning entire URL as code)code !== nullchecks for correct empty-code handlingAll 96 tests pass, typecheck/build/lint clean.