Skip to content
Snippets Groups Projects
Commit 1377013d authored by Yordan Kinkov's avatar Yordan Kinkov
Browse files

Apply Authentication middleware to infohub service

parent 47d5455f
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"golang.org/x/oauth2/clientcredentials" "golang.org/x/oauth2/clientcredentials"
"golang.org/x/sync/errgroup" "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/cache"
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/goadec" "gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/goadec"
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/graceful" "gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/graceful"
...@@ -156,6 +157,15 @@ func main() { ...@@ -156,6 +157,15 @@ func main() {
errFormatter, 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. // Configure the mux.
goainfohubsrv.Mount(mux, infohubServer) goainfohubsrv.Mount(mux, infohubServer)
goahealthsrv.Mount(mux, healthServer) goahealthsrv.Mount(mux, healthServer)
......
...@@ -11,6 +11,7 @@ type Config struct { ...@@ -11,6 +11,7 @@ type Config struct {
Signer signerConfig Signer signerConfig
Metrics metricsConfig Metrics metricsConfig
OAuth oauthConfig OAuth oauthConfig
Auth authConfig
LogLevel string `envconfig:"LOG_LEVEL" default:"INFO"` LogLevel string `envconfig:"LOG_LEVEL" default:"INFO"`
} }
...@@ -56,3 +57,9 @@ type oauthConfig struct { ...@@ -56,3 +57,9 @@ type oauthConfig struct {
ClientSecret string `envconfig:"OAUTH_CLIENT_SECRET" required:"true"` ClientSecret string `envconfig:"OAUTH_CLIENT_SECRET" required:"true"`
TokenURL string `envconfig:"OAUTH_TOKEN_URL" 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"`
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment