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:
adam jones 2025-08-18 15:49:04 +01:00 • committed by GitHub
commit e9fe6f9ab8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 275 additions and 113 deletions

View file

@ -79,7 +79,7 @@ func (h *GitHubHandler) ExchangeToken(ctx context.Context, githubToken string) (
}
// Get user's organizations
orgs, err := h.getGitHubUserOrgs(ctx, githubToken)
orgs, err := h.getGitHubUserOrgs(ctx, user.Login, githubToken)
if err != nil {
return nil, fmt.Errorf("failed to get GitHub organizations: %w", err)
}
@ -138,9 +138,8 @@ func (h *GitHubHandler) getGitHubUser(ctx context.Context, token string) (*GitHu
return &user, nil
}
// getGitHubUserOrgs gets the authenticated user's organizations
func (h *GitHubHandler) getGitHubUserOrgs(ctx context.Context, token string) ([]GitHubUserOrOrg, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, h.baseURL+"/user/orgs", nil)
func (h *GitHubHandler) getGitHubUserOrgs(ctx context.Context, username string, token string) ([]GitHubUserOrOrg, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, h.baseURL+"/users/"+username+"/orgs", nil)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}

View file

@ -23,7 +23,7 @@ import (
const (
githubUserEndpoint = "/user"
githubOrgsEndpoint = "/user/orgs"
githubOrgsEndpoint = "/users/testuser/orgs"
)
func TestGitHubHandler_ExchangeToken(t *testing.T) {
@ -226,7 +226,7 @@ func TestGitHubHandler_ExchangeToken(t *testing.T) {
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(user) //nolint:errcheck
case githubOrgsEndpoint:
case "/users/user with spaces/orgs":
orgs := []v0auth.GitHubUserOrOrg{}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(orgs) //nolint:errcheck
@ -259,7 +259,7 @@ func TestGitHubHandler_ExchangeToken(t *testing.T) {
switch r.URL.Path {
case githubUserEndpoint:
user := v0auth.GitHubUserOrOrg{
Login: "validuser",
Login: "testuser",
ID: 12345,
}
w.Header().Set("Content-Type", "application/json")
@ -290,7 +290,7 @@ func TestGitHubHandler_ExchangeToken(t *testing.T) {
jwtManager := auth.NewJWTManager(cfg)
claims, err := jwtManager.ValidateToken(ctx, response.RegistryToken)
require.NoError(t, err)
assert.Equal(t, "validuser", claims.AuthMethodSubject)
assert.Equal(t, "testuser", claims.AuthMethodSubject)
assert.Empty(t, claims.Permissions) // No permissions because one org has invalid name
})
@ -538,7 +538,7 @@ func TestValidGitHubNames(t *testing.T) {
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(user) //nolint:errcheck
case githubOrgsEndpoint:
case "/users/" + tc.username + "/orgs":
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(tc.orgs) //nolint:errcheck
}
@ -596,7 +596,7 @@ func TestConcurrentTokenExchange(t *testing.T) {
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(user) //nolint:errcheck
case "/user/orgs":
case githubOrgsEndpoint:
orgs := []v0auth.GitHubUserOrOrg{}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(orgs) //nolint:errcheck

View file

@ -12,6 +12,7 @@ const (
)
// Config holds the application configuration
// See .env.example for more documentation
type Config struct {
ServerAddress string `env:"SERVER_ADDRESS" envDefault:":8080"`
DatabaseType DatabaseType `env:"DATABASE_TYPE" envDefault:"mongodb"`