-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.go
50 lines (40 loc) · 1.03 KB
/
interface.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
package token
import "context"
const (
AppName = "tokens"
)
type Service interface {
// 登录接口(颁发Token)
Login(context.Context, *LoginRequest) (*Token, error)
// 退出接口(销毁Token)
Logout(context.Context, *LogoutRequest) (*Token, error)
// 校验Token 是给内部中间层使用 身份校验层
// 校验完后返回Token, 通过Token获取 用户信息
ValiateToken(context.Context, *ValiateToken) (*Token, error)
}
func NewLoginRequest() *LoginRequest {
return &LoginRequest{}
}
type LoginRequest struct {
Username string
Password string
}
func NewLogoutRequest(at, rk string) *LogoutRequest {
return &LogoutRequest{
AccessToken: at,
RefreshToken: rk,
}
}
// 万一的Token泄露, 不知道refresh_token,也没法推出
type LogoutRequest struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
}
func NewValiateToken(at string) *ValiateToken {
return &ValiateToken{
AccessToken: at,
}
}
type ValiateToken struct {
AccessToken string `json:"access_token"`
}