From b128f5ec382f8450751c03dfd3e7a8cf2d5976ec Mon Sep 17 00:00:00 2001 From: Abhishek Shroff Date: Sun, 29 Jun 2025 01:07:21 +0530 Subject: [PATCH] [server][auth][openid] Change config structure --- server/internal/auth/auth.go | 2 +- server/internal/auth/conifg.go | 6 +++--- server/internal/auth/openid/config.go | 4 ++++ server/internal/auth/openid/openid.go | 4 ++-- server/internal/command/config.defaults.yml | 13 +++++++------ 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/server/internal/auth/auth.go b/server/internal/auth/auth.go index b7394eba..49d29d66 100644 --- a/server/internal/auth/auth.go +++ b/server/internal/auth/auth.go @@ -54,7 +54,7 @@ func Init(cfg Config, log zerolog.Logger) error { return errors.New("password backend not recognized: " + cfg.Password.Backend) } - return openid.Init(cfg.OpenIDProviders, log) + return openid.Init(cfg.OpenID, log) } func generateRandomString(n int) string { diff --git a/server/internal/auth/conifg.go b/server/internal/auth/conifg.go index 2cc045a3..3f5de1bc 100644 --- a/server/internal/auth/conifg.go +++ b/server/internal/auth/conifg.go @@ -7,9 +7,9 @@ import ( ) type Config struct { - AutoCreateDomains []string `koanf:"auto_create_domains"` - Password PasswordConfig `koanf:"password"` - OpenIDProviders []openid.ClientConfig `koanf:"openid_providers"` + AutoCreateDomains []string `koanf:"auto_create_domains"` + Password PasswordConfig `koanf:"password"` + OpenID openid.Config `koanf:"openid"` } type PasswordConfig struct { diff --git a/server/internal/auth/openid/config.go b/server/internal/auth/openid/config.go index 30ff439e..2c62bb68 100644 --- a/server/internal/auth/openid/config.go +++ b/server/internal/auth/openid/config.go @@ -1,5 +1,9 @@ package openid +type Config struct { + Clients []ClientConfig `koanf:"clients"` +} + type ClientConfig struct { ID string `koanf:"id"` Name string `koanf:"name"` diff --git a/server/internal/auth/openid/openid.go b/server/internal/auth/openid/openid.go index 68689eb0..db4c1d16 100644 --- a/server/internal/auth/openid/openid.go +++ b/server/internal/auth/openid/openid.go @@ -23,9 +23,9 @@ type Provider struct { var log zerolog.Logger -func Init(cfg []ClientConfig, l zerolog.Logger) error { +func Init(cfg Config, l zerolog.Logger) error { log = l.With().Str("c", "auth.openid").Logger() - for _, c := range cfg { + for _, c := range cfg.Clients { clients[c.ID] = c if _, err := getProviderConfig(c.IssuerURL); err != nil { log.Warn().Err(err).Str("id", c.ID).Str("issuer_url", c.IssuerURL).Msg("Unable to get OpenID config") diff --git a/server/internal/command/config.defaults.yml b/server/internal/command/config.defaults.yml index 61f94fbd..cbd691b4 100644 --- a/server/internal/command/config.defaults.yml +++ b/server/internal/command/config.defaults.yml @@ -47,12 +47,13 @@ auth: bind_password: base_dn: filter_template: - # openid_providers: - # - id: google - # name: Google - # issuer_url: https://accounts.google.com - # client_id: - # client_secret: + # openid: + # clients: + # - id: google + # name: Google + # issuer_url: https://accounts.google.com + # client_id: + # client_secret: jobs: