From 387b89963d91d471565ac4e6b5b54ed4df82392e Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Wed, 25 Sep 2024 15:49:21 +0200 Subject: [PATCH] Allow for static secret --- internal/env/env.go | 7 ++++--- main.go | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/env/env.go b/internal/env/env.go index 251e4c8..e652c66 100644 --- a/internal/env/env.go +++ b/internal/env/env.go @@ -19,10 +19,11 @@ type Config struct { WeatherUnits string `env:"WEATHER_UNITS" envDefault:"metric"` WeatherLanguage string `env:"WEATHER_LANG" envDefault:"en" validate:"bcp47_language_tag"` WeatherDigits bool `env:"WEATHER_DIGITS" envDefault:"false"` - AuthClientID string `env:"AUTH_CLIENT_ID"` - AuthClientSecret string `env:"AUTH_CLIENT_SECRET"` + AuthClientID string `env:"AUTH_CLIENT_ID" validate:"required"` + AuthClientSecret string `env:"AUTH_CLIENT_SECRET" validate:"required"` AuthScopes []string `env:"AUTH_SCOPES" envSeparator:"," envDefault:"openid,email,profile"` - AuthIssuer string `env:"AUTH_ISSUER"` + AuthIssuer string `env:"AUTH_ISSUER" validate:"required,url,endsnotwith=/.well-known/openid-configuration"` + SessionKey string `env:"SESSION_KEY,unset"` } var errParse = errors.New("error parsing environment variables") diff --git a/main.go b/main.go index d5da5d7..f241f43 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,11 @@ func main() { b := services.NewBookmarkService() parsedUrl, _ := url.Parse(env.PublicUrl) - store := sessions.NewCookieStore(securecookie.GenerateRandomKey(32)) + secret := []byte(env.SessionKey) + if len(secret) == 0 { + secret = securecookie.GenerateRandomKey(32) + } + store := sessions.NewCookieStore(secret) store.Options = &sessions.Options{ Domain: parsedUrl.Hostname(), MaxAge: 86400 * 30,