Skip to content

Add OAuth Bearer token authentication support #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Add OAuth Bearer token authentication support #28

wants to merge 4 commits into from

Conversation

zmofei
Copy link
Member

@zmofei zmofei commented Jul 24, 2025

Summary

This PR adds OAuth 2.0 Bearer token authentication to the MCP server. Users can now authenticate requests using Bearer tokens instead of relying only on environment variables.

Changes

  • Added OAuth authentication flow to the HTTP server
  • Modified tools to accept tokens from authenticated requests
  • Tokens passed via Authorization header take precedence over environment variables
  • Added comprehensive authentication documentation

Key Features

  • Per-request authentication - Each request can use its own Bearer token
  • Backwards compatible - Falls back to environment variables if no token provided
  • Standards compliant - Follows OAuth 2.0 and RFC specifications
  • Multi-tenant ready - Different users can use their own API credentials

Configuration

Set the OAuth server URL via environment variable:

export OAUTH_SERVER_URL=https://your-oauth-server.com

Testing

  1. Make a request without authentication to receive OAuth metadata
  2. Complete OAuth flow to obtain Bearer token
  3. Include token in Authorization header for authenticated requests

Documentation

See AUTH.md for detailed authentication flow and implementation details.

Notes

  • Default CORS configuration allows all origins for development
  • Update CORS settings for production use
  • OAuth server URL must be configured via environment variable

zmofei added 4 commits July 24, 2025 21:32
- Remove VERBOSE_ERRORS environment variable logic
- Always show actual error messages instead of generic 'Internal error has occurred.'
- Update all tests to expect actual error messages
- Fix test mocks to properly handle error responses
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.

1 participant