| Filename | Latest commit message | Latest commit date |
|---|---|---|
This pull request introduces significant updates to the authentication system for the MCP Registry Publisher Tool. The changes focus on transitioning to an interface-based authentication system, implementing GitHub OAuth device flow as the default authentication method, and restructuring the codebase for better modularity and extensibility. Adding an interface to the publishing CLI, so that it'll be easier to add more auth methods as they become available. |
||
| .. | ||
| github | ||
| interface.go | ||
| README.md | ||
Authentication System
The publisher tool now uses an interface-based authentication system that allows for multiple authentication mechanisms.
Architecture
Provider Interface
The Provider interface is defined in auth/interface.go and provides the following methods:
GetToken(ctx context.Context) (string, error)- Retrieves or generates an authentication tokenNeedsLogin() bool- Checks if a new login flow is requiredLogin(ctx context.Context) error- Performs the authentication flowName() string- Returns the name of the authentication provider
Available Authentication Providers
1. GitHub OAuth Provider
- Location:
auth/github/oauth.go - Usage: Uses GitHub's device flow for authentication
- Example:
github.NewOAuthProvider(forceLogin, registryURL)
How to Add New Authentication Providers
- Create a new package under
auth/directory (e.g.,auth/custom/) - Implement the
Providerinterface - Add any necessary configuration or initialization functions
- Update the main application to use the new provider
Example Implementation
package custom
import (
"context"
"fmt"
)
type CustomProvider struct {
// your custom fields
}
func NewCustomProvider(config string) *CustomProvider {
return &CustomProvider{
// initialize your provider
}
}
func (cp *CustomProvider) GetToken(ctx context.Context) (string, error) {
// implement token retrieval logic
return "custom-token", nil
}
func (cp *CustomProvider) NeedsLogin() bool {
// implement login check logic
return false
}
func (cp *CustomProvider) Login(ctx context.Context) error {
// implement authentication flow
return nil
}
func (cp *CustomProvider) Name() string {
return "custom-auth"
}
Usage in Main Application
The main application automatically selects the appropriate authentication provider:
- Uses
GitHub OAuth Providerby default - Future providers can be added by extending the provider selection logic
// Create the appropriate auth provider based on configuration
var authProvider auth.Provider
switch authMethod {
case "github-oauth":
log.Println("Using GitHub OAuth for authentication")
authProvider = github.NewOAuthProvider(forceLogin, registryURL)
default:
log.Printf("Unsupported authentication method: %s\n", authMethod)
return
}
// Check if login is needed and perform authentication
ctx := context.Background()
if authProvider.NeedsLogin() {
err := authProvider.Login(ctx)
if err != nil {
log.Printf("Failed to authenticate with %s: %s\n", authProvider.Name(), err.Error())
return
}
}
// Get the token
token, err := authProvider.GetToken(ctx)
This design allows for easy extension and testing of different authentication mechanisms while maintaining a clean separation of concerns.