Skip to content

Commit d800887

Browse files
committed
add debug prints
1 parent 16536d5 commit d800887

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

v2/token/jwt.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"log"
89
"net/http"
910
"slices"
1011
"strings"
@@ -268,13 +269,31 @@ func (j *Service) Set(w http.ResponseWriter, claims Claims) (Claims, error) {
268269
// This allows the OAuth flow to complete successfully
269270
needsCookies := claims.Handshake != nil
270271

272+
if needsCookies {
273+
log.Printf("[ERROR] OAuth handshake request from %s, will set cookie %s=%s",
274+
claims.Handshake.From,
275+
j.JWTCookieName,
276+
tokenString[:10]+"...")
277+
}
278+
271279
// Set the JWT in the header if requested,
272280
// skip setting cookies unless this is part of OAuth handshake
273281
if j.SendJWTHeader && !needsCookies {
282+
log.Printf("[ERROR] Won't set cookie, will write claims to header instead: %v", claims)
274283
w.Header().Set(j.JWTHeaderKey, tokenString)
284+
// reset existing JWT cookies which we might have left after OAuth handshake
285+
jwtCookie := http.Cookie{Name: j.JWTCookieName, Value: "", HttpOnly: true, Path: "/", Domain: j.JWTCookieDomain,
286+
MaxAge: -1, Expires: time.Unix(0, 0), Secure: j.SecureCookies, SameSite: j.SameSite}
287+
http.SetCookie(w, &jwtCookie)
288+
289+
xsrfCookie := http.Cookie{Name: j.XSRFCookieName, Value: "", HttpOnly: true, Path: "/", Domain: j.JWTCookieDomain,
290+
MaxAge: -1, Expires: time.Unix(0, 0), Secure: j.SecureCookies, SameSite: j.SameSite}
291+
http.SetCookie(w, &xsrfCookie)
275292
return claims, nil
276293
}
277294

295+
log.Printf("[ERROR] Cookie setting: %v", claims)
296+
278297
cookieExpiration := 0 // session cookie
279298
if !claims.SessionOnly && claims.Handshake == nil {
280299
cookieExpiration = int(j.CookieDuration.Seconds())
@@ -359,11 +378,11 @@ func (j *Service) IsExpired(claims Claims) bool {
359378

360379
// Reset token's cookies
361380
func (j *Service) Reset(w http.ResponseWriter) {
362-
jwtCookie := http.Cookie{Name: j.JWTCookieName, Value: "", HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain,
381+
jwtCookie := http.Cookie{Name: j.JWTCookieName, Value: "", HttpOnly: true, Path: "/", Domain: j.JWTCookieDomain,
363382
MaxAge: -1, Expires: time.Unix(0, 0), Secure: j.SecureCookies, SameSite: j.SameSite}
364383
http.SetCookie(w, &jwtCookie)
365384

366-
xsrfCookie := http.Cookie{Name: j.XSRFCookieName, Value: "", HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain,
385+
xsrfCookie := http.Cookie{Name: j.XSRFCookieName, Value: "", HttpOnly: true, Path: "/", Domain: j.JWTCookieDomain,
367386
MaxAge: -1, Expires: time.Unix(0, 0), Secure: j.SecureCookies, SameSite: j.SameSite}
368387
http.SetCookie(w, &xsrfCookie)
369388

0 commit comments

Comments
 (0)