MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / BuildSessionCookies

Function BuildSessionCookies

internal/cookie/cookie.go:39–68  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
39func 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.
71func DeleteSession(gc *gin.Context, appCookieSecure bool, sameSite http.SameSite) {

Callers 7

LoginMethod · 0.92
SessionMethod · 0.92
SignUpMethod · 0.92
VerifyEmailMethod · 0.92
VerifyOTPMethod · 0.92
TestBuildSessionCookiesFunction · 0.85
SetSessionFunction · 0.85

Calls 2

GetHostPartsFunction · 0.92
GetDomainNameFunction · 0.92

Tested by 1

TestBuildSessionCookiesFunction · 0.68