token

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingHeader 表示 `Authorization` 请求头为空.
	ErrMissingHeader = errors.New("the length of the `Authorization` header is zero")

	// ErrBlacklistToken 表示存在于黑名单中的 token
	ErrBlacklistToken = errors.New("token has in blacklist and expire")

	// ErrParseToken 表示解析 token 字符串失败
	ErrParseToken = errors.New("parse token error")
)

Functions

func AddToBlacklist

func AddToBlacklist(r *http.Request) error

AddToBlacklist 添加 Token 到黑名单中

func FailureAllClient

func FailureAllClient(tokenId string) error

FailureAllClient 失效所有客户端的 token

func Init

func Init(opts *Options)

Init 使用指定的选项初始化 jwt.

func IsBlacklisted

func IsBlacklisted(token *jwt.Token) bool

IsBlacklisted 检查 Token 是否在黑名单中

func ParseRequest

func ParseRequest(r *http.Request) (string, error)

ParseRequest 从请求头中获取令牌,并将其传递给 ParseToken 函数以解析令牌.

func ParseToken

func ParseToken(r *http.Request) (*jwt.Token, error)

ParseToken 解析令牌字符串为 jwt.Token 对象

func Sign

func Sign(tokenId string) (*response.TokenResponse, error)

Sign 使用 jwtSecret 签发 token,token 的 claims 中会存放传入的 subject.

Types

type Blacklist

type Blacklist struct {
	ID        string `json:"id"`
	ExpiredAt int64  `json:"expired_at"`
}

Blacklist 黑名单中存储的数据结构

type Options

type Options struct {
	// 用于存放唯一用户的字段
	TokenId string
	// jwt 秘钥
	Secret string
	// token 过期时间(单位:小时)
	Expire int
	// 黑名单存储路径
	BlackPath string
}

Options 包含与日志相关的配置项.

Jump to

Keyboard shortcuts

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