Repository navigation
MCP OAuth
lqdflying edited this page Aug 18, 2026
·
3 revisions
ChatHub supports OAuth 2.1 Authorization Code flow with PKCE for MCP plugins. Users only need the MCP server URL — all OAuth metadata is auto-discovered.
-
Auto-discovery — Enter a server URL, click Connect, and the app discovers Client ID, Client Secret, Authorization Endpoint, and Token Endpoint automatically via RFC 9728 (
/.well-known/oauth-protected-resource) and RFC 8414 (/.well-known/oauth-authorization-server). Optional dynamic client registration (RFC 7591). - Popup flow — Authorization opens in a popup window so the plugin editor stays open with all fields intact. After authorizing, the popup closes and the token status updates to "valid".
-
Server-side token storage — OAuth tokens are stored in PostgreSQL (
mcp_oauth_tokenstable) and automatically injected into MCP connections by the tRPC router. No manual token management needed. Background conversation generation reuses those stored tokens after you close the tab; see Background Conversation Generation. - PKCE — All OAuth flows use S256 PKCE for security.
- Token lifecycle — Automatic access token injection, refresh token support, and disconnect/revoke.
- Open Plugin Store → Add Plugin → enter MCP server URL
- If the server supports OAuth, the OAuth section appears with a Connect button
- Click Connect → the app auto-discovers OAuth endpoints
- A popup window opens for the OAuth provider's authorization page
- After authorizing, the popup closes → token status shows "valid"
- Click Test Connection or Install — tokens are injected automatically
Frontend (OAuthConfig.tsx)
→ discoverOAuth (tRPC) → oauthDiscovery.ts (RFC 9728 + RFC 8414)
→ initiateOAuth (tRPC) → oauth.ts (PKCE + state storage)
→ Browser redirect to OAuth provider
→ /oauth/mcp-callback page → oauthCallback (tRPC) → exchangeCodeForTokens
The OAuth redirect_uri is always:
${window.location.origin}/oauth/mcp-callback
It is derived from window.location.origin at runtime and must match in both the authorization request and token exchange.
OAuth tokens are stored in the mcp_oauth_tokens table. A migration safety net (scripts/migrateServerDB/ensureMcpOAuthTokens.cjs) ensures the table exists on every container startup with CREATE TABLE IF NOT EXISTS.
- Home
- Quick Start
- Docker Deployment and Upgrades
- Authentication
- Model Providers
- Knowledge Base and RAG
- MarkItDown Sidecar
- Sandbox (OpenSandbox)
- OpenAI Compatible Cache Matrix
- Model Extension Options
- Memory & Context Compaction
- Background Conversation Generation
- Pasted Text
- Context Export
- Data Backup and Restore
- Image Generation
- Artifacts
- Inline SVG Diagrams
- Tools Hub
- MCP OAuth
- MCP Management
- Agent Skills
- Database
- Development
- Debug and Diagnostics
- Architecture Overview
- Docker Release
- Release Workflow