diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-10-24 08:38:40 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-10-24 08:38:40 +0200 |
| commit | a9927763f43d59c418b264790ccee59defe8ca29 (patch) | |
| tree | 5dfc4f1f1f29d1ef1cbca3406bf57d1667b93f76 /kauth/config.go | |
| parent | ed23d402fec268e163ec895748f43e3254ba3dfd (diff) | |
refactor: Rename packages for clarityv0.3.0
Diffstat (limited to 'kauth/config.go')
| -rw-r--r-- | kauth/config.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/kauth/config.go b/kauth/config.go new file mode 100644 index 0000000..777a22d --- /dev/null +++ b/kauth/config.go @@ -0,0 +1,34 @@ +package kauth + +import ( + "encoding/hex" + "errors" + "os" + + "github.com/martinlehoux/kagamigo/kcore" + "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 = kcore.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 +} |
