From 4588a283a6ba693aa01bf9dbd75e569131145cd5 Mon Sep 17 00:00:00 2001 From: Yordan Kinkov <yordan.kinkov@vereign.com> Date: Thu, 24 Nov 2022 13:42:08 +0200 Subject: [PATCH] Make oauth client not required by default --- cmd/infohub/main.go | 11 +++++++---- internal/config/config.go | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/infohub/main.go b/cmd/infohub/main.go index 1260069..baaba9a 100644 --- a/cmd/infohub/main.go +++ b/cmd/infohub/main.go @@ -80,10 +80,13 @@ func main() { httpClient := httpClient() - // Create an HTTP Client which uses an authentication token. - // The token will auto-refresh as necessary. - 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) + } credentials := credential.New(cfg.Credential.IssuerURI, httpClient) diff --git a/internal/config/config.go b/internal/config/config.go index b4a0439..28aa1fa 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -53,13 +53,13 @@ type metricsConfig 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 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"` } -- GitLab