jwt_auth

package
v0.4.21 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTokenType = errors.New("invalid token type")
	ErrInvalidToken     = errors.New("invalid token string")
	ErrInvalidPayload   = errors.New("invalid payload parameter")
)

Functions

This section is empty.

Types

type JwtAuth

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

JwtAuth jwt鉴权模块,包装常用的jwt工具函数

func (*JwtAuth) GenTokenWithClaims

func (a *JwtAuth) GenTokenWithClaims(payload map[string]interface{}) (string, error)

GenTokenWithClaims 使用用户自定义map生成 jwt token param payload 用户自定义data map return jwt 字符串

func (*JwtAuth) GenTokenWithPayload

func (a *JwtAuth) GenTokenWithPayload(payload Payload) (string, error)

GenTokenWithPayload 生成jwt token 字符串 param payload 用户自定义data, 能序列化为json return jwt 字符串

func (*JwtAuth) GetPayloadFromToken

func (a *JwtAuth) GetPayloadFromToken(token string, payload Payload) error

GetPayloadFromToken 解析token,并尝试读取payload信息 param token token 字符串 payload 用户自定义payload结构体指针 return 解析成功返回nil, 否则返回错误

func (*JwtAuth) GetToken

func (a *JwtAuth) GetToken(token string) (map[string]interface{}, error)

GetToken 解析并获取token结构体 param token token 字符串 return payload map

func (*JwtAuth) GetTokenString

func (a *JwtAuth) GetTokenString(c *http_proxy.Context) (string, error)

GetTokenString 鉴权函数,提取token 字符串 param c http 请求上下文 return token 完整字符串 return error 解析是否发生错误,失败会返回ErrInvalidTokenType

type Option

type Option func(options *Options)

type Options

type Options struct {
	// Enable 是否启用Auth模块
	Enable bool `yaml:"enable"`
	//AuthHeader http头部中用于鉴权的字段名
	AuthHeader string `yaml:"auth_header"`
	//TokenType token 类型 如 Bearer
	TokenType string `yaml:"token_type"`
	//TokenExpires token 过期时间
	TokenExpiresTime int `yaml:"token_expires_time"`
	//TokenRefreshTime token 刷新续期时间
	TokenRefreshTime int `yaml:"token_refresh_time"`
	//Encryption 编码方式,如HS256
	Encryption string `yaml:"encryption"`
	//Secret 密钥
	Secret string `yaml:"secret"`
}

type Payload

type Payload interface {
	Valid() error
}

Payload 自定义payload结构,支持从这个接口序列化和反序列化

Jump to

Keyboard shortcuts

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