Skip to content

fix: Direct OAuth Flow PKCE store mapping for provider identification#108

Merged
jdutton merged 4 commits into
mainfrom
feature/adoption-feedback
Dec 11, 2025
Merged

fix: Direct OAuth Flow PKCE store mapping for provider identification#108
jdutton merged 4 commits into
mainfrom
feature/adoption-feedback

Conversation

@jdutton

@jdutton jdutton commented Dec 11, 2025

Copy link
Copy Markdown
Owner

Summary

Fixes #107 - Direct OAuth Flow now works correctly with Claude Code and MCP Inspector.

Problem

Direct OAuth Flow (client-provided PKCE) was failing with invalid_grant errors because the server wasn't storing authorization code mappings in the PKCE store. This prevented provider identification in multi-provider deployments.

Solution

Always store authorization code mappings in PKCE store, using empty string '' as sentinel value for Direct OAuth Flow:

  • OAuth Proxy Flow: Store non-empty code_verifier (server-generated)
  • Direct OAuth Flow: Store empty string (client will provide code_verifier)

Changes

Core Fix

  • packages/auth/src/providers/base-provider.ts:
    • Always store authorization code mapping (removed conditional)
    • Use empty string sentinel for Direct OAuth Flow
    • Improved logging to distinguish flow types
    • Enhanced security checks in resolveCodeVerifierForTokenExchange()

Testing

  • packages/auth/test/direct-oauth-flow.test.ts (NEW):
    • 11 comprehensive test cases for Direct OAuth Flow
    • Covers authorization, token exchange, and error scenarios
    • Validates provider identification in multi-provider setup

Documentation

  • docs/getting-started/01-overview.md: Framework overview and architecture
  • docs/getting-started/02-http-session-management.md: HTTP session management patterns
  • docs/getting-started/03-tool-registry-http-mode.md: Tool registry for HTTP mode
  • packages/create-mcp-typescript-simple/templates/CLAUDE.md.hbs: Updated scaffolding template

Testing

✅ All validation tests passing (ran vibe-validate validate)
✅ Direct OAuth Flow tests (11 new test cases)
✅ OAuth Proxy Flow tests (existing tests still pass)
✅ Multi-provider routing tests

Breaking Changes

None - this is a bug fix that makes existing functionality work correctly.

Release Notes

Bug Fixes:

  • Fixed Direct OAuth Flow (client-provided PKCE) causing invalid_grant errors
  • Fixed Claude Code integration (OAuth client state preservation)
  • Fixed MCP Inspector integration (Direct OAuth Flow support)
  • Improved provider identification in multi-provider deployments

Documentation:

  • Added comprehensive getting-started guides
  • Improved scaffolding template with HTTP session management notes

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

jdutton and others added 4 commits December 11, 2025 11:56
- Add docs/getting-started/01-overview.md (framework overview)
- Add docs/getting-started/02-http-session-management.md (header-based sessions)
- Add docs/getting-started/03-tool-registry-http-mode.md (critical toolRegistry pattern)
- Update CLAUDE.md.hbs template with Framework Source Code section

Based on real-world adoption feedback from production use case.
Addresses confusion around HTTP mode patterns and session management.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- OAuth Direct Flow provider identification fix
- vibe-validate update to 0.17.4

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Update root version to 0.9.1-rc.2
- Update vibe-validate to 0.17.4

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Implemented PKCE validation logic (sha256 challenge verification)
- Created helper functions to eliminate duplication:
  - createMockProvider(): Reduces mock provider creation boilerplate
  - computeCodeChallenge(): Centralizes PKCE challenge computation
- Reduced duplicated code from 42 lines (14.3%) to near zero
- Fixed ESLint: Use node:crypto instead of crypto

Addresses SonarCloud feedback:
- Completed TODO for PKCE validation
- Eliminated duplicated mock provider patterns

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@jdutton jdutton merged commit e9e1347 into main Dec 11, 2025
7 checks passed
@jdutton jdutton deleted the feature/adoption-feedback branch December 11, 2025 21:31
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.

Bug: Direct OAuth Flow fails with 'invalid_grant' error due to missing PKCE store mapping

1 participant