blob: 777a22d434928ce130b35eb823c5f759346df48f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
}
|