Skip to content

[Feature Request]: OAuth Enhancement following PR 768 #782

@crivetimihai

Description

@crivetimihai

OAuth Enhancement Ticket

Related: PR #768 OAuth 2.0 Support
Status: Follow-up Work
Priority: High
Milestone: Release 0.7.0

Background

PR #768 successfully implemented OAuth 2.0 foundation with Authorization Code and Client Credentials flows. This ticket tracks remaining enhancements identified during review.

High Priority Items

1. Implement Refresh Token Handling

Location: mcpgateway/services/token_storage_service.py:208
Issue: Currently placeholder implementation
Impact: Tokens can't be automatically refreshed when they expire

Requirements:

  • Implement _refresh_access_token() method
  • Add OAuth provider refresh endpoint calls
  • Handle refresh token expiration
  • Update stored tokens after successful refresh
  • Add error handling for refresh failures

2. Enhanced User ID Mapping

Location: mcpgateway/services/oauth_manager.py:561
Issue: Uses placeholder user ID extraction
Impact: Poor user identification and token association

Requirements:

  • Extract real user ID from token response
  • Make userinfo API calls to OAuth providers
  • Support multiple OAuth provider user ID formats
  • Add configurable user ID extraction strategies

3. Token Management UI

Location: Admin UI (mcpgateway/templates/admin.html)
Issue: No interface for managing stored tokens
Impact: No visibility into OAuth authorizations

Requirements:

  • Add "OAuth Tokens" section to Admin UI
  • Display authorized users per gateway
  • Token expiration status and refresh capability
  • Revoke token functionality
  • Bulk token cleanup tools

Medium Priority Items

4. OAuth for Resources and Prompts

Location: mcpgateway/services/gateway_service.py
Issue: OAuth only implemented for tools
Impact: Incomplete OAuth coverage

Requirements:

  • Extend OAuth authentication to resource fetching
  • Add OAuth support for prompt operations
  • Update gateway service to handle OAuth for all entity types
  • Test OAuth flows with all MCP capabilities

5. PKCE Support (OAuth 2.1)

Location: mcpgateway/services/oauth_manager.py
Issue: Missing PKCE for enhanced security
Impact: Less secure authorization flows

Requirements:

  • Generate code verifier and challenge
  • Include PKCE in authorization URLs
  • Validate PKCE in token exchange
  • Support both SHA256 and plain challenge methods

6. Automated Token Cleanup

Location: mcpgateway/services/token_storage_service.py:321
Issue: Manual cleanup only
Impact: Database bloat with expired tokens

Requirements:

  • Scheduled cleanup job for expired tokens
  • Configurable retention policies
  • Cleanup metrics and logging
  • Integration with gateway health checks

Low Priority Items

7. OAuth Provider Templates

Location: Admin UI gateway creation
Issue: Manual OAuth configuration required
Impact: User experience friction

Requirements:

  • Pre-configured OAuth settings for popular providers
  • GitHub, Google, Microsoft provider templates
  • Auto-population of common OAuth endpoints
  • Provider-specific documentation links

8. Advanced Token Features

Location: Various OAuth components
Issue: Basic token handling only
Impact: Limited enterprise features

Requirements:

  • Token introspection with OAuth providers
  • Scope validation and management
  • OAuth audit logging for compliance
  • Token rotation policies

Technical Debt

9. Remove Debug Code

Location: Various files with print() statements
Issue: Debug prints left in production code
Impact: Log noise and unprofessional output

Files to clean:

  • mcpgateway/services/oauth_manager.py:81,97,182,197
  • mcpgateway/services/gateway_service.py:646,658-665,705-725

10. Error Message Improvements

Location: OAuth error handling
Issue: Generic error messages
Impact: Poor developer experience

Requirements:

  • Provider-specific error interpretation
  • Actionable error messages with next steps
  • Error code mapping for common OAuth issues
  • Troubleshooting documentation links

Success Criteria

Definition of Done

  • All refresh token flows work end-to-end
  • User ID extraction works with major OAuth providers
  • Token management UI allows full CRUD operations
  • OAuth works for tools, resources, and prompts
  • PKCE implementation passes security audit
  • Automated cleanup runs without issues
  • Debug code removed from all production files
  • Error messages provide clear next steps

Testing Requirements

  • Unit tests for all new functionality (>90% coverage)
  • Integration tests with real OAuth providers
  • Security testing for PKCE and token handling
  • Performance testing for token operations
  • End-to-end testing with GitHub MCP server

Dependencies

  • OAuth Provider Access: GitHub app registration for testing
  • Security Review: For PKCE and token encryption validation
  • UI/UX Design: For token management interface design
  • Documentation: OAuth setup guides for different providers

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesttriageIssues / Features awaiting triage

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions