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.
This commit is contained in:
parent
d555acb65b
commit
e9fe6f9ab8
1 changed files with 275 additions and 113 deletions
78
tools/publisher/auth/none/none.go
Normal file
78
tools/publisher/auth/none/none.go
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
package none
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/modelcontextprotocol/registry/tools/publisher/auth"
|
||||
)
|
||||
|
||||
type Provider struct {
|
||||
registryURL string
|
||||
token string
|
||||
}
|
||||
|
||||
type TokenResponse struct {
|
||||
RegistryToken string `json:"registry_token"`
|
||||
ExpiresAt int64 `json:"expires_at"`
|
||||
}
|
||||
|
||||
func NewProvider(registryURL string) auth.Provider { //nolint:ireturn
|
||||
return &Provider{
|
||||
registryURL: registryURL,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Provider) GetToken(ctx context.Context) (string, error) {
|
||||
if p.token != "" {
|
||||
return p.token, nil
|
||||
}
|
||||
|
||||
// Get anonymous token from registry
|
||||
if !strings.HasSuffix(p.registryURL, "/") {
|
||||
p.registryURL += "/"
|
||||
}
|
||||
tokenURL := p.registryURL + "v0/auth/none"
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, tokenURL, nil)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error creating request: %w", err)
|
||||
}
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error getting anonymous token: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return "", fmt.Errorf("failed to get anonymous token (status %d): %s", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
var tokenResp TokenResponse
|
||||
if err := json.NewDecoder(resp.Body).Decode(&tokenResp); err != nil {
|
||||
return "", fmt.Errorf("error decoding token response: %w", err)
|
||||
}
|
||||
|
||||
p.token = tokenResp.RegistryToken
|
||||
return p.token, nil
|
||||
}
|
||||
|
||||
func (p *Provider) NeedsLogin() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *Provider) Login(_ context.Context) error {
|
||||
// No login needed for anonymous auth
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Provider) Name() string {
|
||||
return "none"
|
||||
}
|
||||
Loading…
Reference in a new issue