/
tokens.go
63 lines (54 loc) · 1.59 KB
/
tokens.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package model
import (
"crypto/rsa"
"github.com/dgrijalva/jwt-go"
"github.com/google/uuid"
"time"
)
// Token used for returning pairs of id and refresh tokens
type Token struct {
AccessToken
RefreshToken
}
// AccessToken stores token properties that
// are accessed in multiple application layers
type AccessToken struct {
SignedStringToken string `json:"id_token"`
}
// RefreshToken stores token properties that
// are accessed in multiple application layers
type RefreshToken struct {
ID uuid.UUID `json:"-"`
UID uuid.UUID `json:"-"`
SignedStringToken string `json:"refresh_token"`
}
// AccessTokenInfo stores access token's initialize information
type AccessTokenInfo struct {
PublicKey *rsa.PublicKey
PrivateKey *rsa.PrivateKey
Expires int64
}
// RefreshTokenInfo stores refresh token's initialize information
type RefreshTokenInfo struct {
Secret string
Expires int64
}
// AccessTokenCustomClaims holds structure of jwt claims of idToken
type AccessTokenCustomClaims struct {
User *User `json:"user"`
jwt.StandardClaims
}
// RefreshTokenCustomClaims holds the payload of a refresh token
// This can be used to extract user id for subsequent
// application operations (IE, fetch user in Redis)
type RefreshTokenCustomClaims struct {
UID uuid.UUID `json:"uid"`
jwt.StandardClaims
}
// RefreshTokenData holds the actual signed jwt string along with the ID
// We return the id, so it can be used without re-parsing the JWT from signed string
type RefreshTokenData struct {
SignedStringToken string
ID uuid.UUID
ExpiresIn time.Duration
}