jwtauth

package
v7.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2020 License: MIT Imports: 5 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(ctx context.Context, tokenString string) error

DestroyToken 销毁令牌

func (*JWTAuth) GenerateToken

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

GenerateToken 生成令牌

func (*JWTAuth) ParseUserID

func (a *JWTAuth) ParseUserID(ctx context.Context, 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(ctx context.Context, tokenString string, expiration time.Duration) error
	// 检查令牌是否存在
	Check(ctx context.Context, 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