MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetRefreshTokenCookie

Function GetRefreshTokenCookie

backend/api/auth/header.go:103–122  ·  view source on GitHub ↗

GetRefreshTokenCookie creates a cookie for the refresh token. token="" => unset (clears cookie) Path is "/" to allow logout to delete the token from database. Security is maintained via HttpOnly, Secure, and SameSite=Strict.

(origin, token string, duration time.Duration)

Source from the content-addressed store, hash-verified

101// Path is "/" to allow logout to delete the token from database.
102// Security is maintained via HttpOnly, Secure, and SameSite=Strict.
103func GetRefreshTokenCookie(origin, token string, duration time.Duration) *http.Cookie {
104 if token == "" {
105 return &http.Cookie{
106 Name: RefreshTokenCookieName,
107 Value: "",
108 Expires: time.Unix(0, 0),
109 Path: "/",
110 }
111 }
112 isHTTPS := strings.HasPrefix(origin, "https")
113 return &http.Cookie{
114 Name: RefreshTokenCookieName,
115 Value: token,
116 MaxAge: int(duration.Seconds()),
117 Path: "/",
118 HttpOnly: true,
119 Secure: isHTTPS,
120 SameSite: http.SameSiteStrictMode,
121 }
122}
123
124// GetRefreshTokenFromCookie extracts the refresh token from request headers.
125func GetRefreshTokenFromCookie(header http.Header) string {

Callers 5

SignupMethod · 0.92
RefreshMethod · 0.92
finalizeLoginMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected