jwt: increase leeway and add some tests

also export a constant for the Cookie name

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2025-10-11 14:14:21 +02:00
parent c4bc88cd2e
commit a768dac29d
6 changed files with 42 additions and 9 deletions

View File

@@ -49,8 +49,7 @@ const (
)
const (
basicRealm = "Basic realm=\"SFTPGo\""
jwtCookieKey = "jwt"
basicRealm = "Basic realm=\"SFTPGo\""
)
var (
@@ -142,7 +141,7 @@ func createAndSetCookie(w http.ResponseWriter, r *http.Request, claims *jwt.Clai
func setCookie(w http.ResponseWriter, r *http.Request, cookiePath, cookieValue string, duration time.Duration) {
http.SetCookie(w, &http.Cookie{
Name: jwtCookieKey,
Name: jwt.CookieKey,
Value: cookieValue,
Path: cookiePath,
Expires: time.Now().Add(duration),
@@ -156,7 +155,7 @@ func setCookie(w http.ResponseWriter, r *http.Request, cookiePath, cookieValue s
func removeCookie(w http.ResponseWriter, r *http.Request, cookiePath string) {
invalidateToken(r)
http.SetCookie(w, &http.Cookie{
Name: jwtCookieKey,
Name: jwt.CookieKey,
Value: "",
Path: cookiePath,
Expires: time.Unix(0, 0),