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)
| 101 | // Path is "/" to allow logout to delete the token from database. |
| 102 | // Security is maintained via HttpOnly, Secure, and SameSite=Strict. |
| 103 | func 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. |
| 125 | func GetRefreshTokenFromCookie(header http.Header) string { |
no outgoing calls
no test coverage detected