diff --git a/cmd/policy/main.go b/cmd/policy/main.go index 72d5b57a0cc8fa20350cbe24f20ef37216056229..7c0364b6915286a9aee0ca859dc0e3e3d32e3e1e 100644 --- a/cmd/policy/main.go +++ b/cmd/policy/main.go @@ -62,10 +62,13 @@ func main() { httpClient := httpClient() - // Create an HTTP Client which automatically issues and carries an OAuth2 token. - // The token will auto-refresh when its expiration is near. - oauthCtx := context.WithValue(context.Background(), oauth2.HTTPClient, httpClient) - oauthClient := newOAuth2Client(oauthCtx, cfg.OAuth.ClientID, cfg.OAuth.ClientSecret, cfg.OAuth.TokenURL) + oauthClient := httpClient + if cfg.Auth.Enabled { + // Create an HTTP Client which automatically issues and carries an OAuth2 token. + // The token will auto-refresh when its expiration is near. + oauthCtx := context.WithValue(context.Background(), oauth2.HTTPClient, httpClient) + oauthClient = newOAuth2Client(oauthCtx, cfg.OAuth.ClientID, cfg.OAuth.ClientSecret, cfg.OAuth.TokenURL) + } // create cache client cache := cache.New(cfg.Cache.Addr, cache.WithHTTPClient(oauthClient)) diff --git a/internal/config/config.go b/internal/config/config.go index f203bd462e76b90d9b364fd0335aa311b1e9bee4..5073ffd9bb0052349642b808e92b78454095b700 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -59,9 +59,9 @@ type ocmConfig struct { } type oauthConfig struct { - ClientID string `envconfig:"OAUTH_CLIENT_ID" required:"true"` - ClientSecret string `envconfig:"OAUTH_CLIENT_SECRET" required:"true"` - TokenURL string `envconfig:"OAUTH_TOKEN_URL" required:"true"` + ClientID string `envconfig:"OAUTH_CLIENT_ID"` + ClientSecret string `envconfig:"OAUTH_CLIENT_SECRET"` + TokenURL string `envconfig:"OAUTH_TOKEN_URL"` } type refresherConfig struct { @@ -69,7 +69,7 @@ type refresherConfig struct { } type authConfig struct { - Enabled bool `envconfig:"AUTH_ENABLED" default:"true"` + Enabled bool `envconfig:"AUTH_ENABLED" default:"false"` JwkURL string `envconfig:"AUTH_JWK_URL"` RefreshInterval time.Duration `envconfig:"AUTH_REFRESH_INTERVAL" default:"1h"` }