Documentation ¶
Index ¶
Constants ¶
View Source
const ( TOKEN_COOKIE_NAME = "access_token" TOKEN_GIN_KEY_NAME = "access_token" )
View Source
const (
AppName = "token"
)
Variables ¶
View Source
var AuthFailed = exception.NewAuthFailed("用户名或者密码不正确")
View Source
var (
CookieNotFound = exception.NewAuthFailed("cookie %s not found", TOKEN_COOKIE_NAME)
)
Functions ¶
This section is empty.
Types ¶
type LoginRequest ¶
func NewLoginRequest ¶
func NewLoginRequest() *LoginRequest
type LogoutRequest ¶
type LogoutRequest struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` }
万一的Token泄露, 不知道refresh_token,也没法推出
type Service ¶
type Service interface { // 登录接口(颁发Token) Login(context.Context, *LoginRequest) (*Token, error) // 退出接口(销毁Token) Logout(context.Context, *LogoutRequest) error // 校验Token 是给内部中间层使用 身份校验层 // 校验完后返回Token, 通过Token获取 用户信息 ValiateToken(context.Context, *ValiateToken) (*Token, error) }
type Token ¶
type Token struct { // 该Token是颁发 UserId int64 `json:"user_id"` // 人的名称, user_name UserName string `json:"username" gorm:"column:username"` // 办法给用户的访问令牌(用户需要携带Token来访问接口) AccessToken string `json:"access_token"` // 过期时间(2h), 单位是秒 AccessTokenExpiredAt int `json:"access_token_expired_at"` // 刷新Token RefreshToken string `json:"refresh_token"` // 刷新Token过期时间(7d) RefreshTokenExpiredAt int `json:"refresh_token_expired_at"` // 创建时间 CreatedAt int64 `json:"created_at"` // 更新实现 UpdatedAt int64 `json:"updated_at"` // 额外补充信息, gorm忽略处理 Role user.Role `gorm:"-"` }
type ValiateToken ¶
type ValiateToken struct {
AccessToken string `json:"access_token"`
}
func NewValiateToken ¶
func NewValiateToken(at string) *ValiateToken
Click to show internal directories.
Click to hide internal directories.