Skip to content

fix: handle multiple OAuth callback formats in browser auth - #19

Merged
cemalturkcan merged 2 commits into
mainfrom
fix/robust-callback-parsing
Apr 8, 2026
Merged

fix: handle multiple OAuth callback formats in browser auth#19
cemalturkcan merged 2 commits into
mainfrom
fix/robust-callback-parsing

Conversation

@cemalturkcan

Copy link
Copy Markdown
Owner

Summary

Based on PR #18 by @Steffen025 with review fixes applied.

  • Extracts parseCallbackCode() helper for four OAuth callback input formats
  • Fixes hash+query string interaction bug (code=abc#state was not stripped correctly)
  • Throws on OAuth error responses instead of silent fallthrough
  • Uses !== null instead of truthiness for empty code handling
  • Adds test suite with 14 cases covering all formats and edge cases

Original 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

  • Strip # fragment before URLSearchParams parsing (fixes code=abc#state=xyz regression)
  • Detect and throw on OAuth ?error= responses
  • Throw when a valid URL has no code parameter (instead of returning entire URL as code)
  • code !== null checks for correct empty-code handling
  • 5 additional test cases for edge cases

All 96 tests pass, typecheck/build/lint clean.

Steffen025 and others added 2 commits April 7, 2026 22:13
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
@cemalturkcan
cemalturkcan merged commit 14597e0 into main Apr 8, 2026
1 check passed
@github-actions

github-actions Bot commented Apr 8, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.4.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants