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

Apply Authentication middleware to policy service

parent 6acfabda
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,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/graceful"
goahealth "gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/policy/gen/health"
goahealthsrv "gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/policy/gen/http/health/server"
......@@ -179,6 +180,15 @@ func main() {
// Apply middlewares on the servers
policyServer.Evaluate = header.Middleware()(policyServer.Evaluate)
// Apply Authentication middleware if enabled
if cfg.Auth.Enabled {
m, err := auth.NewMiddleware(cfg.Auth.JwkURL, cfg.Auth.RefreshInterval, httpClient)
if err != nil {
logger.Fatal("failed to create authentication middleware", zap.Error(err))
}
policyServer.Use(m.Handler())
}
// Configure the mux.
goapolicysrv.Mount(mux, policyServer)
goahealthsrv.Mount(mux, healthServer)
......
......@@ -13,6 +13,7 @@ type Config struct {
OCM ocmConfig
OAuth oauthConfig
Refresher refresherConfig
Auth authConfig
LogLevel string `envconfig:"LOG_LEVEL" default:"INFO"`
}
......@@ -66,3 +67,9 @@ type oauthConfig struct {
type refresherConfig struct {
PollInterval time.Duration `envconfig:"REFRESHER_POLL_INTERVAL" default:"10s"`
}
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.
Finish editing this message first!
Please register or to comment