Repository navigation
fix(auth): support Claude Code loopback callbacks - #24
massimoalbarello wants to merge 1 commit into
Conversation
|
Closing after re-evaluating the compatibility tradeoff. This patch works around current Claude Code behavior by modifying Better Auth compiled internals and relaxing redirect validation for every localhost-based native client. That is broader and more brittle than the problem warrants. RFC 8252 requires dynamic-port matching for loopback IP literals and explicitly discourages localhost: https://www.rfc-editor.org/rfc/rfc8252.html#section-7.3 The current MCP specification also requires native clients to send application_type=native during Dynamic Client Registration (SEP-837): modelcontextprotocol/modelcontextprotocol#837 Claude Code currently omits that classification and hardcodes localhost; the same client-side interoperability problem has been reported upstream: anthropics/claude-code#82096 Better Auth intentionally limits port-flexible matching to IP literals, so Context Use should retain that security boundary rather than carry a dependency patch for one client. We will treat this as a known Claude Code compatibility limitation and rebase the onboarding work in #25 directly onto main. If first-class compatibility becomes essential before Claude fixes the client, we can consider a narrowly scoped, application-owned adapter instead. |
After passkey registration, new owners now see a centered agent bootstrap instead of a second manual setup form. Skipping opens the ordinary entity creation route; when no self entity exists, that first submission goes through the knowledge-profile boundary before the workspace renders. Signed-in setup and OAuth consent screens omit the public header and placeholder account name. create_entity accepts isSelf and delegates that case to KnowledgeProfilesService, preserving atomic self-entity creation and the one-owner invariant without adding profile-specific MCP tools. The prompt limits the first pass to five other entities and three pages, sends the user to the populated Pages view, and points incompatible agents to the manual first-entity route and MCP settings. The Vite development proxy now sends only the MCP transport and asset-transfer namespace to the backend, leaving the frontend-owned /mcp/authorize consent route available during local testing. Context Use retains its existing standards-based loopback redirect validation; this PR does not include the closed Claude Code workaround from #24.
Claude Code dynamically registers a public
localhostcallback withoutapplication_typeand can listen on a different ephemeral port during authorization. Better Auth currently defaults that registration to a web client and requires exact ports forlocalhost, preventing the standard MCP OAuth flow.This pins a narrow Better Auth patch that infers
nativeonly for public registrations with an omitted type and exact HTTP loopback callbacks, then permitslocalhostport variance while preserving exact scheme, hostname, path, and query matching. Explicit web clients remain rejected. Integration coverage exercises the Claude Code registration shape, changed callback port, explicit-web rejection, and mismatched-path rejection.The dependency patch can be removed once equivalent upstream behavior is available.