jwtauth

package
v0.0.0-...-68868ce Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JWTAuth

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

JWTAuth jwt认证

func New

func New(store Storer, opts ...Option) *JWTAuth

New 创建认证实例

func (*JWTAuth) DestroyToken

func (a *JWTAuth) DestroyToken(tokenString string) error

DestroyToken 销毁令牌

func (*JWTAuth) GenerateToken

func (a *JWTAuth) GenerateToken(userID string) (auth.TokenInfo, error)

GenerateToken 生成令牌

func (*JWTAuth) ParseUserID

func (a *JWTAuth) ParseUserID(tokenString string) (string, error)

ParseUserID 解析用户ID

func (*JWTAuth) Release

func (a *JWTAuth) Release() error

Release 释放资源

type Option

type Option func(*options)

Option 定义参数项

func SetExpired

func SetExpired(expired int) Option

SetExpired 设定令牌过期时长(单位秒,默认7200)

func SetKeyfunc

func SetKeyfunc(keyFunc jwt.Keyfunc) Option

SetKeyfunc 设定验证key的回调函数

func SetSigningKey

func SetSigningKey(key interface{}) Option

SetSigningKey 设定签名key

func SetSigningMethod

func SetSigningMethod(method jwt.SigningMethod) Option

SetSigningMethod 设定签名方式

type Storer

type Storer interface {
	// 放入令牌,指定到期时间
	Set(tokenString string, expiration time.Duration) error
	// 检查令牌是否存在
	Check(tokenString string) (bool, error)
	// 关闭存储
	Close() error
}

Storer 黑名单存储接口

Directories

Path Synopsis
store

Jump to

Keyboard shortcuts

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