forked from AccelByte/osin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookie.go
35 lines (30 loc) · 826 Bytes
/
cookie.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) 2021 AccelByte Inc. All Rights Reserved.
// This is licensed software from AccelByte Inc, for limitations
// and restrictions contact your company contract manager.
package osin
import (
"net/http"
"net/url"
"time"
)
// AddTokenInCookie adds token cookie in the response header
func AddTokenInCookie(response *Response, token string, tokenType string, tokenExpiration int64, cookieDomain string) {
cookie := http.Cookie{
Name: tokenType,
Value: token,
Expires: time.Unix(tokenExpiration, 0),
Secure: true,
HttpOnly: true,
SameSite: http.SameSiteNoneMode,
Path: "/",
}
if cookieDomain != "" {
parsed, err := url.Parse(cookieDomain)
if err == nil {
cookie.Domain = parsed.Host
}
}
if v := cookie.String(); v != "" {
response.Headers.Add("Set-Cookie", v)
}
}