-
Notifications
You must be signed in to change notification settings - Fork 664
/
auth_token.go
54 lines (48 loc) · 1.47 KB
/
auth_token.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
package obj
import (
"github.com/hwholiday/learning_tools/ddd-auth2-example/domain/dto"
"time"
)
type AuthToken struct {
APPID string `json:"appid"`
Secret string `json:"secret"`
OpenID string `json:"open_id"`
AccessToken string `json:"access_token"` // 网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同
AccessTokenTimeline int64 `json:"access_token_timeline"` // access_token 到期时间毫秒
RefreshToken string `json:"refresh_token"` // 用户刷新access_token
RefreshTokenTimeline int64 `json:"refresh_token_timeline"` // refresh_token 到期时间毫秒
Scope string `json:"scope"` // 用户授权的作用域,使用逗号(,)分隔
}
func (a AuthToken) TOSimple() dto.AuthTokenSimple {
return dto.AuthTokenSimple{
OpenID: a.OpenID,
AccessToken: a.AccessToken,
ExpiresIn: a.GetExpiresIn(),
RefreshToken: a.RefreshToken,
Scope: a.Scope,
}
}
func (a AuthToken) GetExpiresIn() int64 {
now := time.Now().Unix()
t := a.AccessTokenTimeline - now
if t > 0 {
return t
}
return 0
}
func (a AuthToken) AccessTokenExpired() bool {
now := time.Now().Unix()
t := a.AccessTokenTimeline - now
if t > 0 {
return false
}
return true
}
func (a AuthToken) RefreshTokenExpired() bool {
now := time.Now().Unix()
t := a.RefreshTokenTimeline - now
if t > 0 {
return false
}
return true
}