Files
probo/pkg/server/api/console/v1/cookie.go
gearnode 123a538d82 Embded frontend inside go binary
This will simplify the self hosting of the platform.

Signed-off-by: gearnode <bryan@frimin.fr>
2025-03-09 15:30:28 +01:00

39 lines
966 B
Go

package console_v1
import (
"net/http"
)
// setSessionCookie sets a session cookie in the response
func setSessionCookie(w http.ResponseWriter, sessionID string, cfg AuthConfig) {
// Sign the session ID
signedValue := signCookieValue(sessionID, cfg.CookieSecret)
cookie := &http.Cookie{
Name: cfg.CookieName,
Value: signedValue,
Path: cfg.CookiePath,
Domain: cfg.CookieDomain,
Secure: cfg.CookieSecure,
HttpOnly: cfg.CookieHTTPOnly,
MaxAge: int(cfg.SessionDuration.Seconds()),
SameSite: http.SameSiteLaxMode,
}
http.SetCookie(w, cookie)
}
// clearSessionCookie clears the session cookie
func clearSessionCookie(w http.ResponseWriter, cfg AuthConfig) {
cookie := &http.Cookie{
Name: cfg.CookieName,
Value: "",
Path: cfg.CookiePath,
Domain: cfg.CookieDomain,
Secure: cfg.CookieSecure,
HttpOnly: cfg.CookieHTTPOnly,
MaxAge: -1,
SameSite: http.SameSiteLaxMode,
}
http.SetCookie(w, cookie)
}