jwtauth

package
v0.0.0-...-96aa6bb Latest Latest
Warning

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

Go to latest
Published: May 11, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrTokenExpired token 已经过期
	ErrTokenExpired = errors.New("Token is expired")
	//ErrTokenNotValidYet token不可用
	ErrTokenNotValidYet = errors.New("Token not active yet")
	//ErrTokenMalformed token不合法
	ErrTokenMalformed = errors.New("That's not even a token")
	//ErrTokenInvalid token 不可用
	ErrTokenInvalid = errors.New("Couldn't handle this token")
	//SignKey  签名key
	SignKey = "test"
)

Functions

func GetSignKey

func GetSignKey() string

GetSignKey 返回签名Key

func JWTAuth

func JWTAuth() gin.HandlerFunc

JWTAuth json web token gin 中间间,用于在分组路由中校验请求是否带有token

func SetSignKey

func SetSignKey(key string) string

SetSignKey 设置签名KEY

Types

type CustomClaims

type CustomClaims struct {
	ID    int64  `json:"id"`
	Name  string `json:"name"`
	Email string `json:"email"`
	jwt.StandardClaims
}

CustomClaims 用户关键信息

type JWT

type JWT struct {
	SigningKey []byte
}

JWT jwt对象定义,含有jwt需要的签名KEY

func NewJWT

func NewJWT() *JWT

NewJWT 生成一个新的json web token

func (*JWT) CreateToken

func (j *JWT) CreateToken(claims CustomClaims) (string, error)

CreateToken 创建一个token

func (*JWT) ParseToken

func (j *JWT) ParseToken(tokenString string) (*CustomClaims, error)

ParseToken token逆转,获得用户信息

func (*JWT) RefreshToken

func (j *JWT) RefreshToken(tokenString string) (string, error)

RefreshToken 刷新Token

Jump to

Keyboard shortcuts

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