go17/vblog/apps/token/interface.go

43 lines
987 B
Go
Raw Normal View History

2024-12-01 11:06:09 +08:00
package token
2024-12-01 14:54:54 +08:00
import "context"
2024-12-01 11:06:09 +08:00
// 业务域
type Service interface {
2024-12-01 14:54:54 +08:00
UserService
InnterService
2024-12-01 11:06:09 +08:00
}
// 1. 外部
2024-12-01 14:54:54 +08:00
type UserService interface {
2024-12-01 11:06:09 +08:00
// 颁发令牌 登录
2024-12-01 14:54:54 +08:00
IssueToken(context.Context, *IssueTokenRequest) (*Token, error)
2024-12-01 11:06:09 +08:00
// 撤销令牌 退出
2024-12-01 14:54:54 +08:00
RevolkToken(context.Context, *RevolkTokenRequest) (*Token, error)
}
type RevolkTokenRequest struct {
// 访问令牌
AccessToken string `json:"access_token"`
// 刷新令牌, 构成一对避免AccessToken 泄露,用户可以直接 revolk
RefreshToken string `json:"refresh_token"`
}
type IssueTokenRequest struct {
Username string `json:"username"`
Password string `json:"password"`
// 记住我, Token可能1天过期, 过去时间调整为7天
RememberMe bool `json:"remember_me"`
2024-12-01 11:06:09 +08:00
}
// 内部
2024-12-01 14:54:54 +08:00
type InnterService interface {
2024-12-01 11:06:09 +08:00
// 令牌校验
2024-12-01 14:54:54 +08:00
ValidateToken(context.Context, *ValidateTokenRequest) (*Token, error)
}
type ValidateTokenRequest struct {
// 访问令牌
AccessToken string `json:"access_token"`
2024-12-01 11:06:09 +08:00
}