diff --git a/cmd/registry/main.go b/cmd/registry/main.go index 53ba0d2..c86a50b 100644 --- a/cmd/registry/main.go +++ b/cmd/registry/main.go @@ -74,18 +74,6 @@ func main() { // Initialize authentication services authService := auth.NewAuthService(cfg) - if cfg.RequireAuth { - log.Println("Authentication is required for package publishing") - - if cfg.GithubClientID == "" || cfg.GithubClientSecret == "" { - log.Println("Warning: GitHub OAuth credentials not configured but authentication is required") - } else { - log.Println("GitHub OAuth authentication is configured") - } - } else { - log.Println("Authentication is optional for package publishing") - } - // Initialize HTTP server server := api.NewServer(cfg, registryService, authService) diff --git a/internal/api/handlers/v0/publish.go b/internal/api/handlers/v0/publish.go index 009d664..8d8f066 100644 --- a/internal/api/handlers/v0/publish.go +++ b/internal/api/handlers/v0/publish.go @@ -65,9 +65,20 @@ func PublishHandler(registry service.RegistryService, authService auth.Service) token = authHeader[7:] } + // Determine authentication method based on server name prefix + var authMethod model.AuthMethod + switch { + case strings.HasPrefix(serverDetail.Name, "io.github"): + authMethod = model.AuthMethodGitHub + // Additional cases can be added here for other prefixes + default: + // Keep the default auth method as AuthMethodNone + authMethod = model.AuthMethodNone + } + // Setup authentication info a := model.Authentication{ - Method: model.AuthMethodGitHub, + Method: authMethod, Token: token, RepoRef: serverDetail.Name, } diff --git a/internal/auth/service.go b/internal/auth/service.go index a46c91a..54a9f01 100644 --- a/internal/auth/service.go +++ b/internal/auth/service.go @@ -39,11 +39,6 @@ func (s *AuthServiceImpl) CheckAuthStatus(ctx context.Context, statusToken strin // ValidateAuth validates authentication credentials func (s *AuthServiceImpl) ValidateAuth(ctx context.Context, auth model.Authentication) (bool, error) { - // If authentication is not required, allow access - if !s.config.RequireAuth { - return true, nil - } - // If authentication is required but not provided if auth.Method == "" || auth.Method == model.AuthMethodNone { return false, ErrAuthRequired diff --git a/internal/config/config.go b/internal/config/config.go index a6139f9..e4f559e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -17,7 +17,6 @@ type Config struct { // GitHub OAuth settings GithubClientID string `env:"GITHUB_CLIENT_ID" envDefault:""` GithubClientSecret string `env:"GITHUB_CLIENT_SECRET" envDefault:""` - RequireAuth bool `env:"REQUIRE_AUTH" envDefault:"false"` // Whether to require authentication for publishing } // NewConfig creates a new configuration with default values