From 09cf06c90502449df7d09345555bbcdce5f6adea Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 29 Jun 2019 12:40:39 +0200 Subject: [PATCH] [#41] Set default cookie values in all providers (#45) Signed-off-by: Knut Ahlers --- main.go | 3 +-- plugins/auth/google/auth.go | 2 ++ plugins/auth/ldap/auth.go | 2 ++ plugins/auth/oidc/auth.go | 2 ++ plugins/auth/simple/auth.go | 2 ++ plugins/auth/yubikey/auth.go | 2 ++ plugins/cookie.go | 7 +++++++ 7 files changed, 18 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index e7c33fe..8d98526 100644 --- a/main.go +++ b/main.go @@ -73,8 +73,7 @@ func init() { } // Set sane defaults for main configuration - mainCfg.Cookie.Prefix = "nginx-sso" - mainCfg.Cookie.Expire = 3600 + mainCfg.Cookie = plugins.DefaultCookieConfig() mainCfg.Listen.Addr = "127.0.0.1" mainCfg.Listen.Port = 8082 mainCfg.Login.DefaultRedirect = "debug" diff --git a/plugins/auth/google/auth.go b/plugins/auth/google/auth.go index ad4ef05..5eb3e92 100644 --- a/plugins/auth/google/auth.go +++ b/plugins/auth/google/auth.go @@ -64,6 +64,8 @@ func (a *AuthGoogleOAuth) Configure(yamlSource []byte) (err error) { } `yaml:"providers"` }{} + envelope.Cookie = plugins.DefaultCookieConfig() + if err := yaml.Unmarshal(yamlSource, &envelope); err != nil { return err } diff --git a/plugins/auth/ldap/auth.go b/plugins/auth/ldap/auth.go index 77c7cf8..326c8d2 100644 --- a/plugins/auth/ldap/auth.go +++ b/plugins/auth/ldap/auth.go @@ -62,6 +62,8 @@ func (a *AuthLDAP) Configure(yamlSource []byte) error { } `yaml:"providers"` }{} + envelope.Cookie = plugins.DefaultCookieConfig() + if err := yaml.Unmarshal(yamlSource, &envelope); err != nil { return err } diff --git a/plugins/auth/oidc/auth.go b/plugins/auth/oidc/auth.go index 382dd6e..412cc08 100644 --- a/plugins/auth/oidc/auth.go +++ b/plugins/auth/oidc/auth.go @@ -67,6 +67,8 @@ func (a *AuthOIDC) Configure(yamlSource []byte) (err error) { } `yaml:"providers"` }{} + envelope.Cookie = plugins.DefaultCookieConfig() + if err := yaml.Unmarshal(yamlSource, &envelope); err != nil { return err } diff --git a/plugins/auth/simple/auth.go b/plugins/auth/simple/auth.go index 58c0709..b965246 100644 --- a/plugins/auth/simple/auth.go +++ b/plugins/auth/simple/auth.go @@ -45,6 +45,8 @@ func (a *AuthSimple) Configure(yamlSource []byte) error { } `yaml:"providers"` }{} + envelope.Cookie = plugins.DefaultCookieConfig() + if err := yaml.Unmarshal(yamlSource, &envelope); err != nil { return err } diff --git a/plugins/auth/yubikey/auth.go b/plugins/auth/yubikey/auth.go index f6e1364..a348c30 100644 --- a/plugins/auth/yubikey/auth.go +++ b/plugins/auth/yubikey/auth.go @@ -44,6 +44,8 @@ func (a *AuthYubikey) Configure(yamlSource []byte) error { } `yaml:"providers"` }{} + envelope.Cookie = plugins.DefaultCookieConfig() + if err := yaml.Unmarshal(yamlSource, &envelope); err != nil { return err } diff --git a/plugins/cookie.go b/plugins/cookie.go index a5cba19..e664a74 100644 --- a/plugins/cookie.go +++ b/plugins/cookie.go @@ -19,3 +19,10 @@ func (c CookieConfig) GetSessionOpts() *sessions.Options { HttpOnly: true, } } + +func DefaultCookieConfig() CookieConfig { + return CookieConfig{ + Prefix: "nginx-sso", + Expire: 3600, + } +}