jwtplus

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: MIT Imports: 8 Imported by: 1

README

go-jwt

go-jwt

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Storer = NewStore()

Storer 黑名单存储接口

Functions

func DestroyToken

func DestroyToken(token string) error

销毁令牌

func GenToken

func GenToken(data interface{}) (string, error)

生成授权信息

func SetHandle

func SetHandle(jwtHandle *Handle)

修改默认的Handle方法

func ValidToken

func ValidToken(token string) bool

校验token信息是否有效

func ValidTokenHttp added in v1.0.6

func ValidTokenHttp(req *http.Request) bool

校验http请求是否有有效的授权认证信息

Types

type Config

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

jwt配置类,

func NewConfig

func NewConfig(key []byte) *Config

创建配置实例对象

type Handle

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

jwt操作

func NewHandle

func NewHandle(conf *Config) *Handle

创建jwtHandle实例对象

func (*Handle) ExtractClaimsFromToken added in v1.0.6

func (r *Handle) ExtractClaimsFromToken(token *jwt.Token) MapClaims

ExtractClaimsFromToken help to extract the JWT claims from token

func (*Handle) ParseHttp

func (r *Handle) ParseHttp(req *http.Request) (MapClaims, error)

从http请求中获取token,然后解析token

func (*Handle) ParseToken

func (r *Handle) ParseToken(token string) (MapClaims, error)

func (*Handle) SetKey

func (r *Handle) SetKey(key []byte) *Handle

func (*Handle) TokenDestroy added in v1.0.6

func (r *Handle) TokenDestroy(token string) error
销毁令牌

临时存放到redis ,每次校验判断是否在redis中,如果在表示token无效

func (*Handle) TokenGenerator added in v1.0.6

func (r *Handle) TokenGenerator(data interface{}) (string, error)

生成token

func (*Handle) TokenParse added in v1.0.6

func (r *Handle) TokenParse(token string) (*jwt.Token, error)

解析token,返回claims信息, 如果token无效,则error将会展示错误信息, 如果token有效,customClaims将会返回连接用户的信息

func (*Handle) TokenValid added in v1.0.6

func (r *Handle) TokenValid(token string) bool

根据token校验token是否有效 如果token有效,则返回true,否则返回false

func (*Handle) ValidHttp

func (r *Handle) ValidHttp(req *http.Request) bool

从Http的请求中获取Token,校验token是否有效 如果token有效,则返回true,如果无效,则返回false

type MapClaims added in v1.0.2

type MapClaims map[string]interface{}

func ParseToken

func ParseToken(token string) (MapClaims, error)

解析token是否有效,如果有效,则返回userdata实例对象

func ParseTokenHttp added in v1.0.6

func ParseTokenHttp(req *http.Request) (MapClaims, error)

从http请求中获取用户信息,如果用户已经获得授权,则返回用户信息,error为nil, 如果用户没有授权信息,或者授权信息已经过期,则errors为错误信息

type Store

type Store struct {
}

Store buntdb存储

func NewStore

func NewStore() *Store

func (*Store) Check

func (a *Store) Check(tokenString string) (bool, error)

检查令牌是否存在

func (*Store) Set

func (a *Store) Set(tokenString string, expiration int64) (bool, error)

放入令牌,指定到期时间

Jump to

Keyboard shortcuts

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