auth: Add GitHub OIDC auth (#278)
Adds support for auth'ing to the registry via [GitHub Actions OIDC](https://docs.github.com/en/actions/concepts/security/openid-connect). Fixes #271 ## Motivation and Context People will probably want to publish to the registry from CI environments. DNS auth can work here fine (https://github.com/modelcontextprotocol/registry/issues/270). But for people who haven't set up DNS, the standard GitHub device flow won't really work here. We could make this nice by supporting GitHub Actions OIDC. ## How Has This Been Tested? Tested locally with a real GitHub OIDC token from a personal repo. ## 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
This commit is contained in:
parent
e9fe6f9ab8
commit
12ab632d32
1 changed files with 802 additions and 193 deletions
|
|
@ -14,8 +14,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/modelcontextprotocol/registry/tools/publisher/auth"
|
||||
"github.com/modelcontextprotocol/registry/tools/publisher/auth/github"
|
||||
"github.com/modelcontextprotocol/registry/tools/publisher/auth/none"
|
||||
)
|
||||
|
||||
// Server structure types for JSON generation
|
||||
|
|
@ -104,8 +102,7 @@ func publishCommand() error {
|
|||
publishFlags.StringVar(®istryURL, "registry-url", "", "URL of the registry (required)")
|
||||
publishFlags.StringVar(&mcpFilePath, "mcp-file", "", "path to the MCP file (required)")
|
||||
publishFlags.BoolVar(&forceLogin, "login", false, "force a new login even if a token exists")
|
||||
publishFlags.StringVar(&authMethod, "auth-method", "github",
|
||||
"authentication method (github for authenticated, none for anonymous) (default: github)")
|
||||
publishFlags.StringVar(&authMethod, "auth-method", "github-at", "authentication method (default: github-at)")
|
||||
|
||||
// Set custom usage function
|
||||
publishFlags.Usage = func() {
|
||||
|
|
@ -117,7 +114,7 @@ func publishCommand() error {
|
|||
fmt.Fprint(os.Stdout, " --registry-url string URL of the registry (required)\n")
|
||||
fmt.Fprint(os.Stdout, " --mcp-file string path to the MCP file (required)\n")
|
||||
fmt.Fprint(os.Stdout, " --login force a new login even if a token exists\n")
|
||||
fmt.Fprint(os.Stdout, " --auth-method string authentication method (github for authenticated, none for anonymous) (default: github)\n")
|
||||
fmt.Fprint(os.Stdout, " --auth-method string authentication method (default: github-at)\n")
|
||||
}
|
||||
|
||||
if err := publishFlags.Parse(os.Args[2:]); err != nil {
|
||||
|
|
@ -137,12 +134,15 @@ func publishCommand() error {
|
|||
|
||||
var authProvider auth.Provider // Determine the authentication method
|
||||
switch authMethod {
|
||||
case "github":
|
||||
log.Println("Using GitHub OAuth for authentication")
|
||||
authProvider = github.NewOAuthProvider(forceLogin, registryURL)
|
||||
case "github-at":
|
||||
log.Println("Using GitHub Access Token for authentication")
|
||||
authProvider = auth.NewGitHubATProvider(forceLogin, registryURL)
|
||||
case "github-oidc":
|
||||
log.Println("Using GitHub Actions OIDC for authentication")
|
||||
authProvider = auth.NewGitHubOIDCProvider(registryURL)
|
||||
case "none":
|
||||
log.Println("Using anonymous authentication")
|
||||
authProvider = none.NewProvider(registryURL)
|
||||
authProvider = auth.NewNoneProvider(registryURL)
|
||||
default:
|
||||
return fmt.Errorf("unsupported authentication method: %s", authMethod)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue