registry/tools/publisher/auth
Repository files (latest commit first)
Filename Latest commit message Latest commit date
adam jones e9fe6f9ab8
feat: Add creds for GitHub auth, add "none" auth to publisher (#276)
## 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.
2025-08-18 15:49:04 +01:00
..
github feat: Add creds for GitHub auth, add "none" auth to publisher (#276) 2025-08-18 15:49:04 +01:00
none feat: Add creds for GitHub auth, add "none" auth to publisher (#276) 2025-08-18 15:49:04 +01:00
interface.go Publish Auth Interface (#112) 2025-05-30 15:05:15 -04:00
README.md feat: Add creds for GitHub auth, add "none" auth to publisher (#276) 2025-08-18 15:49:04 +01:00

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 token
  • NeedsLogin() bool - Checks if a new login flow is required
  • Login(ctx context.Context) error - Performs the authentication flow
  • Name() 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

  1. Create a new package under auth/ directory (e.g., auth/custom/)
  2. Implement the Provider interface
  3. Add any necessary configuration or initialization functions
  4. 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:

  1. Uses GitHub OAuth Provider by default
  2. 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.