token

package
v0.0.0-...-da91ef8 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingHeader = errors.New("the length of the `Authorization` header is zero")

ErrMissingHeader 表示 `Authorization` 请求头为空.

Functions

func Init

func Init(key string, expiration time.Duration)

Init 设置包级别的配置 config, config 会用于本包后面的 token 签发和解析.

func Parse

func Parse(tokenString string, key string) (map[string]interface{}, error)

Parse 使用指定的密钥 key 解析 token,解析成功返回 token 上下文,否则报错.

func ParseRequest

func ParseRequest(c *gin.Context) (map[string]interface{}, error)

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

func Sign

func Sign(claims map[string]interface{}) (tokenString string, err error)

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

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config 包括 token 包的配置选项.

Jump to

Keyboard shortcuts

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