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/cookie.go | |
feat: Extract from other repo
Diffstat (limited to 'auth/cookie.go')
| -rw-r--r-- | auth/cookie.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/auth/cookie.go b/auth/cookie.go new file mode 100644 index 0000000..61349fa --- /dev/null +++ b/auth/cookie.go @@ -0,0 +1,21 @@ +package auth + +import ( + "fmt" + "net/http" + "time" + + "github.com/martinlehoux/kagamigo/core" +) + +func CraftCookie(id core.ID, config AuthConfig) http.Cookie { + expiresAt := time.Now().Add(24 * time.Hour) + cookieValue := encrypt(config.CookieSecret, fmt.Sprintf("%s:%d", id.String(), expiresAt.Unix())) + return http.Cookie{ + Domain: config.Domain, + Name: "authentication", + Value: cookieValue, + Expires: expiresAt, + Path: "/", + } +} |
