-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes_auth.go
61 lines (51 loc) · 1.31 KB
/
types_auth.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
package sfdc
import (
"encoding/json"
"time"
)
type CachedTokenCallback func() (string, error)
type SetTokenCallback func(token string, expiresIn time.Duration) error
type Token struct {
ID string `json:"id"`
Scope string `json:"scope"`
TokenType string `json:"token_type"`
AccessToken string `json:"access_token"`
InstanceURL string `json:"instance_url"`
IssuedAt string `json:"issued_at"`
Signature string `json:"signature"`
expiresAt time.Time
}
func (token *Token) SetExpiry(exp int) *Token {
token.expiresAt = time.Unix(0, int64(exp)*int64(time.Millisecond))
return token
}
func (token *Token) IsExpired() bool {
return time.Now().After(token.expiresAt)
}
type TokenIntrospection struct {
Active bool `json:"active"`
Scope string `json:"scope"`
ClientID string `json:"client_id"`
Username string `json:"username"`
Sub string `json:"sub"`
TokenType string `json:"token_type"`
Exp int `json:"exp"`
Iat int `json:"iat"`
Nbf int `json:"nbf"`
}
type JWTClaim struct {
Iss string `json:"iss"`
Aud string `json:"aud"`
Sub string `json:"sub"`
Exp string `json:"exp"`
}
type JWTHeader struct {
Alg string `json:"alg"`
}
func (token *Token) JSON() string {
b, err := json.Marshal(token)
if err != nil {
return ""
}
return string(b)
}