Minor cleanup of challenges code, bind session http cookies to issued tokens

This commit is contained in:
WeebDataHoarder
2025-04-07 19:00:53 +02:00
parent 0968e6feae
commit e08a5697f6
6 changed files with 323 additions and 183 deletions

27
utils/cookie.go Normal file
View File

@@ -0,0 +1,27 @@
package utils
import (
"net/http"
"time"
)
var CookiePrefix = ".go-away-"
func SetCookie(name, value string, expiry time.Time, w http.ResponseWriter) {
http.SetCookie(w, &http.Cookie{
Name: name,
Value: value,
Expires: expiry,
SameSite: http.SameSiteLaxMode,
Path: "/",
})
}
func ClearCookie(name string, w http.ResponseWriter) {
http.SetCookie(w, &http.Cookie{
Name: name,
Value: "",
Expires: time.Now().Add(-1 * time.Hour),
MaxAge: -1,
SameSite: http.SameSiteLaxMode,
})
}