diff --git a/cmd/infohub/main.go b/cmd/infohub/main.go index 138bf4b4048dca2abf3a4e207b1f53deb9b3b27c..2166616c3b2700260929be4de9dc90937b491db2 100644 --- a/cmd/infohub/main.go +++ b/cmd/infohub/main.go @@ -21,6 +21,7 @@ import ( "golang.org/x/oauth2/clientcredentials" "golang.org/x/sync/errgroup" + "gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/auth" "gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/cache" "gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/goadec" "gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/graceful" @@ -156,6 +157,15 @@ func main() { errFormatter, ) + // Apply Authentication middleware if enabled + if cfg.Auth.Enabled { + m, err := auth.NewMiddleware(cfg.Auth.JwkURL, cfg.Auth.RefreshInterval, httpClient) + if err != nil { + log.Fatalf("failed to create authentication middleware: %v", err) + } + infohubServer.Use(m.Handler()) + } + // Configure the mux. goainfohubsrv.Mount(mux, infohubServer) goahealthsrv.Mount(mux, healthServer) diff --git a/internal/config/config.go b/internal/config/config.go index cd463954a1680cb041bce54807f9732a2f2519e7..b4a04398737da04a860402ab21fa34e02ed5fd1e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -11,6 +11,7 @@ type Config struct { Signer signerConfig Metrics metricsConfig OAuth oauthConfig + Auth authConfig LogLevel string `envconfig:"LOG_LEVEL" default:"INFO"` } @@ -56,3 +57,9 @@ type oauthConfig struct { ClientSecret string `envconfig:"OAUTH_CLIENT_SECRET" required:"true"` TokenURL string `envconfig:"OAUTH_TOKEN_URL" required:"true"` } + +type authConfig struct { + Enabled bool `envconfig:"AUTH_ENABLED" default:"true"` + JwkURL string `envconfig:"AUTH_JWK_URL"` + RefreshInterval time.Duration `envconfig:"AUTH_REFRESH_INTERVAL" default:"1h"` +}