| Filename | Latest commit message | Latest commit date |
|---|---|---|
## Motivation and Context - Adds credentials for the new MCP Registry Login GitHub Apps (local, staging, prod) - Adds support for "none" auth to publisher ## How Has This Been Tested? - Tested publisher workflows locally - Unit and integration tests passing ## Breaking Changes None ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [x] My code follows the repository's style guidelines - [x] New and existing tests pass locally - [x] I have added appropriate error handling - [x] I have added or updated documentation as needed --- Merging based on Tadas's approval review, and only making minor docs changes on top of that. |
||
| .. | ||
| github | ||
| none | ||
| 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":
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.