token

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package token 令牌管理

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Install

func Install(mod string, db *orm.DB)

Types

type Claims

type Claims interface {
	jwt.Claims

	// UserID 获取用户的唯一编号
	//
	// 可以关联某一用户的所有登录令牌。
	UserID() string

	// BaseToken 关联的基础令牌
	//
	// 仅在刷新令牌中,此值不为空。
	BaseToken() string
}

Claims 自定义 Claims 需要实现的接口

func BuildClaims

func BuildClaims() Claims

func NewClaims

func NewClaims(uid string) Claims

type Tokens

type Tokens[T Claims] struct {
	*jwt.JWT[T]
	// contains filtered or unexported fields
}

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]) BlockToken

func (tks *Tokens[T]) BlockToken(token string) error

BlockToken 丢弃令牌

时长为 New 中传递的 expired 的两倍。

func (*Tokens[T]) BlockUID

func (tks *Tokens[T]) BlockUID(uid string) error

BlockUID 丢弃 UserID 关联的所有令牌

时长为 New 中传递的 expires 的两倍。 包括后续生成的令牌,一般用于禁止用户登录等操作。

func (*Tokens[T]) ClaimsIsBlocked

func (tks *Tokens[T]) ClaimsIsBlocked(c T) bool

func (*Tokens[T]) New

func (tks *Tokens[T]) New(ctx *web.Context, status int, access T) web.Responser

New 签发新的令牌

access 普通的访问令牌; refresh 刷新令牌;

func (*Tokens[T]) RecoverUID

func (tks *Tokens[T]) RecoverUID(uid string) error

RecoverUID 恢复该用户的登录权限

func (*Tokens[T]) TokenIsBlocked

func (tks *Tokens[T]) TokenIsBlocked(token string) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL