diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-10-24 07:20:10 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-10-24 07:20:29 +0200 |
| commit | 18476c6cba2d5d2bb3ecf3ad136dacbf41d0360e (patch) | |
| tree | a7a958ff7a4bf14ed7f7ee3ffd9c84b7592facbd /auth/config.go | |
feat: Extract from other repo
Diffstat (limited to 'auth/config.go')
| -rw-r--r-- | auth/config.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/auth/config.go b/auth/config.go new file mode 100644 index 0000000..6a55839 --- /dev/null +++ b/auth/config.go @@ -0,0 +1,34 @@ +package auth + +import ( + "encoding/hex" + "errors" + "os" + + "github.com/martinlehoux/kagamigo/core" + "golang.org/x/exp/slog" +) + +var ( + ErrCookieBadLength = errors.New("cookie secret must be 32 bytes") +) + +type AuthConfig struct { + Domain string + CookieSecret []byte +} + +func LoadCookieSecret(cookieSecretString string) []byte { + cookiesSecret, err := hex.DecodeString(cookieSecretString) + if err != nil { + err = core.Wrap(err, "error decoding cookie secret") + slog.Error(err.Error()) + os.Exit(1) + } + if len(cookiesSecret) != 32 { + slog.Error(ErrCookieBadLength.Error()) + os.Exit(1) + } + slog.Info("cookie secret loaded") + return cookiesSecret +} |
