Documentation
¶
Overview ¶
Package token 令牌管理
Index ¶
- func Install(mod string, db *orm.DB)
- type BuildResponseFunc
- type Claims
- type Config
- 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]) GetToken(ctx *web.Context) string
- func (tks *Tokens[T]) GetValue(ctx *web.Context) (T, bool)
- func (tks *Tokens[T]) Middleware(next web.HandlerFunc) web.HandlerFunc
- 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 BuildResponseFunc ¶
type Claims ¶
type Claims interface { jwt.Claims // UserID 获取用户的唯一编号 // // 可以关联某一用户的所有登录令牌。 UserID() string // BaseToken 关联的基础令牌 // // 仅在刷新令牌中,此值不为空。 BaseToken() string }
Claims 自定义 Claims 需要实现的接口
func BuildClaims ¶
func BuildClaims() Claims
type Config ¶
type Config struct { // expires 表示令牌的过期时间,单位为秒; Expired int `xml:"expired,attr" json:"expired" yaml:"expired"` // 表示刷新令牌的过期时间,单位为秒,要长于 expired。 // 同时也被作为丢弃令牌的回收时间。 // 如果为零,则自动赋值为 Expired * 2。 Refreshed int `xml:"refreshed,attr" json:"refreshed" yaml:"refreshed"` HMAC []*hmac `xml:"hmac" json:"hmac" yaml:"hmac"` // contains filtered or unexported fields }
func (*Config) SanitizeConfig ¶
func (cnf *Config) SanitizeConfig() *app.ConfigError
type Tokens ¶
type Tokens[T Claims] struct { // contains filtered or unexported fields }
Tokens 令牌管理
func NewTokens ¶
func NewTokens[T Claims](mod string, s *web.Server, db *orm.DB, bc jwt.BuildClaimsFunc[T], cnf *Config, jobTitle string) (*Tokens[T], error)
NewTokens 声明令牌管理对象
func (*Tokens[T]) BlockUID ¶
BlockUID 丢弃 UserID 关联的所有令牌
时长为 New 中传递的 expires 的两倍。 包括后续生成的令牌,一般用于禁止用户登录等操作。
func (*Tokens[T]) ClaimsIsBlocked ¶
func (*Tokens[T]) Middleware ¶
func (tks *Tokens[T]) Middleware(next web.HandlerFunc) web.HandlerFunc
func (*Tokens[T]) RecoverUID ¶
RecoverUID 恢复该用户的登录权限
func (*Tokens[T]) TokenIsBlocked ¶
Click to show internal directories.
Click to hide internal directories.