BuildSessionCookies returns the pair of session cookies (host-scoped and domain-scoped) to set on the response. Transport-agnostic so non-gin callers (the service layer, gRPC handlers) can produce them as side-effects.
(hostname, sessionID string, appCookieSecure bool, sameSite http.SameSite)
| 37 | // domain-scoped) to set on the response. Transport-agnostic so non-gin |
| 38 | // callers (the service layer, gRPC handlers) can produce them as side-effects. |
| 39 | func BuildSessionCookies(hostname, sessionID string, appCookieSecure bool, sameSite http.SameSite) []*http.Cookie { |
| 40 | host, _ := parsers.GetHostParts(hostname) |
| 41 | domain := parsers.GetDomainName(hostname) |
| 42 | if domain != "localhost" { |
| 43 | domain = "." + domain |
| 44 | } |
| 45 | day := 60 * 60 * 24 |
| 46 | return []*http.Cookie{ |
| 47 | { |
| 48 | Name: constants.AppCookieName + "_session", |
| 49 | Value: sessionID, |
| 50 | MaxAge: day, |
| 51 | Path: "/", |
| 52 | Domain: host, |
| 53 | Secure: appCookieSecure, |
| 54 | HttpOnly: true, |
| 55 | SameSite: sameSite, |
| 56 | }, |
| 57 | { |
| 58 | Name: constants.AppCookieName + "_session_domain", |
| 59 | Value: sessionID, |
| 60 | MaxAge: day, |
| 61 | Path: "/", |
| 62 | Domain: domain, |
| 63 | Secure: appCookieSecure, |
| 64 | HttpOnly: true, |
| 65 | SameSite: sameSite, |
| 66 | }, |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // DeleteSession sets session cookies to expire. |
| 71 | func DeleteSession(gc *gin.Context, appCookieSecure bool, sameSite http.SameSite) { |