-
Notifications
You must be signed in to change notification settings - Fork 17
/
tokenpair.go
28 lines (24 loc) · 778 Bytes
/
tokenpair.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
package jwt
import "encoding/json"
// TokenPair holds the access token and refresh token response.
type TokenPair struct {
AccessToken json.RawMessage `json:"access_token,omitempty"`
RefreshToken json.RawMessage `json:"refresh_token,omitempty"`
}
// NewTokenPair accepts raw access and refresh token
// and returns a structure which holds both of them,
// ready to be sent to the client as JSON.
func NewTokenPair(accessToken, refreshToken []byte) TokenPair {
return TokenPair{
AccessToken: BytesQuote(accessToken),
RefreshToken: BytesQuote(refreshToken),
}
}
// BytesQuote returns a double-quoted []byte slice representing "b".
func BytesQuote(b []byte) []byte {
dst := make([]byte, len(b)+2)
dst[0] = '"'
copy(dst[1:], b)
dst[len(dst)-1] = '"'
return dst
}