From 18476c6cba2d5d2bb3ecf3ad136dacbf41d0360e Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Tue, 24 Oct 2023 07:20:10 +0200 Subject: feat: Extract from other repo --- auth/cookie.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 auth/cookie.go (limited to 'auth/cookie.go') 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: "/", + } +} -- cgit v1.3