Overview
OAuth 2.0 authentication enables secure, user-delegated access to MCP servers. Bifrost handles:- Automatic token refresh - Tokens are refreshed before expiration
- PKCE support - For public clients without client secrets
- Dynamic registration - Automatic client registration (RFC 7591)
- OAuth discovery - Discover endpoints from server URLs
- Token management - Store and revoke OAuth tokens
OAuth Flow
Bifrost implements the Authorization Code flow, the most secure and widely-supported OAuth flow:Configuration
Basic OAuth Setup
Configure OAuth authentication when creating an MCP client:- Web UI
- API
- Go SDK
- Navigate to MCP Gateway and click New MCP Server
- Select HTTP or SSE as connection type
- Set Auth Type to OAuth 2.0
- Provide OAuth configuration:
- Client ID: Your OAuth application’s client ID
- Client Secret: (Optional for PKCE) Your OAuth application’s secret
- Authorize URL: OAuth provider’s authorization endpoint
- Token URL: OAuth provider’s token endpoint
- Scopes: Comma-separated list of requested scopes
- Click Authorize to start the OAuth flow
- Complete the authorization in the browser
- MCP client will be created with the OAuth token
Advanced OAuth Configuration
PKCE for Public Clients
For applications without a client secret, use PKCE (Proof Key for Code Exchange):Dynamic Client Registration
If your OAuth server supports RFC 7591, Bifrost can automatically register a client:- Discover OAuth endpoints from
server_url - Register a new client using
registration_url - Use the registered client ID for authorization
OAuth Discovery
Bifrost can automatically discover OAuth endpoints from your MCP server’s metadata:/.well-known/oauth-authorization-server(RFC 8414)/.well-known/openid-configuration- Server MCP metadata
Token Management
View OAuth Token Status
Check the status of an OAuth configuration:pending: User hasn’t authorized yetauthorized: Token is valid and activefailed: Authorization failed or token is invalid
Automatic Token Refresh
Bifrost automatically refreshes OAuth tokens before expiration. No action required - tokens are refreshed transparently during tool execution.Revoke OAuth Token
Revoke an OAuth token when you want to disconnect:- Revokes the token with the OAuth provider
- Deletes the token from Bifrost
- Removes the OAuth configuration
- The MCP client can still be used if auth_type is changed
Common OAuth Providers
GitHub
- Configuration
- Setup Steps
- Configuration
- Setup Steps
Custom OAuth Server
For your own OAuth server:Troubleshooting
OAuth Flow Doesn’t Start
Problem:authorize_url not returned when creating MCP client
Solutions:
- Ensure
auth_typeis set to"oauth" - Check that
oauth_configis provided in the request - Verify
authorize_urlis specified orserver_urlis provided for discovery
Token Refresh Fails
Problem: Tools fail with “OAuth token expired” or “OAuth token invalid” Solutions:- Check if the refresh token is still valid
- Revoke and re-authorize:
DELETE /api/oauth/config/{id}then create a new client - Verify the OAuth provider hasn’t revoked the token
- Check that scopes are still sufficient
Authorization Callback Hangs
Problem: Redirect to/api/oauth/callback doesn’t complete
Solutions:
- Ensure Bifrost is accessible at the registered callback URL
- Check network connectivity between Bifrost and OAuth provider
- Verify the
stateparameter matches (for CSRF protection) - Check Bifrost logs for errors:
grep -i oauth /var/log/bifrost
MCP Client Won’t Connect with OAuth
Problem: MCP client shows “error” state with OAuth configured Solutions:- Verify OAuth token is still valid:
GET /api/oauth/config/{id}/status - Check that OAuth token has required scopes
- Ensure MCP server accepts the
Authorization: Bearer {token}header - Test HTTP connectivity to MCP server
API Reference
Create MCP Client with OAuth
POST/api/mcp/client
OAuthFlowInitiation with authorize_url
Complete OAuth Flow
POST/api/mcp/client/{mcp_client_id}/complete-oauth
Called after user authorizes and is redirected back. Bifrost automatically handles the code exchange.
Response: SuccessResponse
Get OAuth Config Status
GET/api/oauth/config/{oauth_config_id}/status
Returns current status of OAuth configuration and token information.
Response: OAuthConfigStatus
Revoke OAuth Token
DELETE/api/oauth/config/{oauth_config_id}
Revokes the token and removes OAuth configuration.
Response: SuccessResponse
Best Practices
- Use HTTPS - Always use HTTPS for OAuth flows. OAuth providers won’t accept HTTP callback URLs in production.
- Secure Client Secrets - Store client secrets in environment variables or secure vaults, not in version control.
- Rotate Tokens - Periodically revoke and re-authorize OAuth tokens for enhanced security.
- Monitor Token Status - Check token status regularly, especially before critical operations.
- Handle Refresh Failures - If token refresh fails, prompt user to re-authorize rather than silently failing.
- Limit Scopes - Request only the scopes your MCP tools actually need.
- Log OAuth Operations - Keep audit logs of OAuth authorizations and token usage.
Security Considerations
- Token Storage - Bifrost stores OAuth tokens in the database encrypted. Never log or expose tokens.
- PKCE Requirement - For public clients, PKCE is automatically enabled and verified.
- State Parameter - CSRF protection via state parameter is enforced in OAuth flows.
- Token Expiration - Tokens are automatically refreshed, reducing the window of vulnerability.
- Revocation Support - Tokens can be revoked immediately if compromised.

