Documentation
¶
Overview ¶
Package token 令牌管理
Index ¶
- func Install(mod string, db *orm.DB)
- type Claims
- type Tokens
- func (tks *Tokens[T]) BlockToken(token string) error
- func (tks *Tokens[T]) BlockUID(uid string) error
- func (tks *Tokens[T]) ClaimsIsBlocked(c T) bool
- func (tks *Tokens[T]) New(ctx *web.Context, status int, access T) web.Responser
- func (tks *Tokens[T]) RecoverUID(uid string) error
- func (tks *Tokens[T]) TokenIsBlocked(token string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Claims ¶
type Claims interface { jwt.Claims // UserID 获取用户的唯一编号 // // 可以关联某一用户的所有登录令牌。 UserID() string // BaseToken 关联的基础令牌 // // 仅在刷新令牌中,此值不为空。 BaseToken() string }
Claims 自定义 Claims 需要实现的接口
func BuildClaims ¶
func BuildClaims() Claims
type Tokens ¶
Tokens 令牌管理
func NewTokens ¶
func NewTokens[T Claims](s *web.Server, mod string, db *orm.DB, bc jwt.BuildClaimsFunc[T], expires, refreshes int, jobTitle string) (*Tokens[T], error)
NewTokens 声明 token 管理对象
expires 表示 token 的过期时间,单位为秒; refreshes 表示刷新令牌的过期时间,单位为秒,如果为 0 则采用用 expires * 2 作为默认值; jobTitle 表示后台回收 token 服务的显示名称;
func (*Tokens[T]) BlockUID ¶
BlockUID 丢弃 UserID 关联的所有令牌
时长为 New 中传递的 expires 的两倍。 包括后续生成的令牌,一般用于禁止用户登录等操作。
func (*Tokens[T]) ClaimsIsBlocked ¶
func (*Tokens[T]) RecoverUID ¶
RecoverUID 恢复该用户的登录权限
func (*Tokens[T]) TokenIsBlocked ¶
Click to show internal directories.
Click to hide internal directories.