@@ -312,6 +312,24 @@ func WithConfig(c config.SessionConfig) SessionStoreOption {
312312 }
313313 sessions .cookieHandler = securecookie .New (cookieHashKey , cookieEncKey )
314314 }
315+ if c .UnsafeCookieTemplate {
316+ unsafeCookieTmpl := func () http.Cookie {
317+ defaultTmpl := defaultSessionCookieTemplate ()
318+ return http.Cookie {
319+ Name : defaultTmpl .Name ,
320+ Path : defaultTmpl .Path ,
321+ Domain : defaultTmpl .Domain ,
322+ Expires : defaultTmpl .Expires ,
323+ MaxAge : defaultTmpl .MaxAge ,
324+ // NOTE: Secure needs to be true so that the SameSite = None works
325+ // Enables calling a deployed backend from a local ui client version running on localhost
326+ Secure : true ,
327+ HttpOnly : false ,
328+ SameSite : http .SameSiteNoneMode ,
329+ }
330+ }
331+ sessions .cookieTemplate = unsafeCookieTmpl
332+ }
315333
316334 sessions .sessionMaker = NewSessionMaker (WithIdleSessionTTLSeconds (c .IdleSessionTTLSeconds ), WithMaxSessionTTLSeconds (c .MaxSessionTTLSeconds ))
317335
@@ -333,16 +351,18 @@ func WithCookieHandler(h models.CookieHandler) SessionStoreOption {
333351 }
334352}
335353
354+ func defaultSessionCookieTemplate () http.Cookie {
355+ return http.Cookie {
356+ Name : SessionCookieName ,
357+ Path : "/" ,
358+ Secure : true ,
359+ HttpOnly : true ,
360+ SameSite : http .SameSiteLaxMode }
361+ }
362+
336363func NewSessionStore (options ... SessionStoreOption ) (* SessionStore , error ) {
337364 sessions := SessionStore {
338- cookieTemplate : func () http.Cookie {
339- return http.Cookie {
340- Name : SessionCookieName ,
341- Path : "/" ,
342- Secure : true ,
343- HttpOnly : true ,
344- SameSite : http .SameSiteLaxMode }
345- },
365+ cookieTemplate : defaultSessionCookieTemplate ,
346366 }
347367 for _ , opt := range options {
348368 err := opt (& sessions )
0 commit comments