From a9927763f43d59c418b264790ccee59defe8ca29 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Tue, 24 Oct 2023 08:38:40 +0200 Subject: refactor: Rename packages for clarity --- kauth/cookie.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 kauth/cookie.go (limited to 'kauth/cookie.go') diff --git a/kauth/cookie.go b/kauth/cookie.go new file mode 100644 index 0000000..edc30b7 --- /dev/null +++ b/kauth/cookie.go @@ -0,0 +1,21 @@ +package kauth + +import ( + "fmt" + "net/http" + "time" + + "github.com/martinlehoux/kagamigo/kcore" +) + +func CraftCookie(id kcore.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