jwt

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: GPL-3.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenExpired     error = errors.New("token is expired")
	TokenNotValidYet error = errors.New("token not active yet")
	TokenMalformed   error = errors.New("that's not even a token")
	TokenInvalid     error = errors.New("invalid token")
	ErrInvalidToken  error = errors.New("invalid token")
)

定义错误

Functions

func CreateToken added in v1.0.8

func CreateToken(m map[string]string, keys ...string) string

创建token

func ParseToken1 added in v1.0.8

func ParseToken1(tokenString string, keys ...string) (map[string]string, bool)

解析token

Types

type Auther

type Auther interface {
	// 生成令牌
	GenerateToken() (TokenInfo, error)
}

Auther 认证接口

type JWTAuth

type JWTAuth struct {
	Options *options
}

JWTAuth jwt认证

func New

func New(opts ...Option) JWTAuth

New 创建认证实例

func (*JWTAuth) GenerateToken

func (a *JWTAuth) GenerateToken() (TokenInfo, error)

GenerateToken 生成令牌

func (*JWTAuth) ParseToken

func (a *JWTAuth) ParseToken(tokenString string, keys string) (map[string]interface{}, error)

ParseToken 解析令牌

func (*JWTAuth) SetClaims

func (a *JWTAuth) SetClaims(claims jwt.MapClaims)

SetClaims 设定SetClaims

func (*JWTAuth) SetExpired

func (a *JWTAuth) SetExpired(expired int)

SetExpired 设定令牌过期时长(unit, default3600)

func (*JWTAuth) SetKey

func (a *JWTAuth) SetKey(key []byte)

SetKey 设定签名key

func (*JWTAuth) SetKeyFunc

func (a *JWTAuth) SetKeyFunc(key []byte)

SetKeyFunc 设定签名keyFunc

func (*JWTAuth) SetKeyfunc

func (a *JWTAuth) SetKeyfunc(keyFunc jwt.Keyfunc)

SetKeyfunc 设定验证key的回调函数

func (*JWTAuth) SetSigningKey

func (a *JWTAuth) SetSigningKey(key []byte)

SetSigningKey 设定签名key

func (*JWTAuth) SetSigningMethod

func (a *JWTAuth) SetSigningMethod(method jwt.SigningMethod)

SetSigningMethod 设定签名方式

type NewFunc

type NewFunc func(*JWTAuth)

type Option

type Option func(*options)

Option 定义参数项

type TokenInfo

type TokenInfo interface {
	// 获取访问令牌
	GetAccessToken() string
	// 获取令牌类型
	GetTokenType() string
	// 获取令牌到期时间戳
	GetExpiresAt() int64
	// JSON编码
	EncodeToJSON() ([]byte, error)
}

TokenInfo 令牌信息

Jump to

Keyboard shortcuts

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