jws

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenExpired     = errors.New("授权已过期")
	TokenNotValidYet = errors.New("授权未生效")
	TokenMalformed   = errors.New("无权限访问")
	TokenInvalid     = errors.New("无权限访问")
	TokenHeaderName  = "Authorization"
	Claims           = "claims"
	DefaultSignKey   = "defaultSignKey"
	TokenTimeout     = 2592000 // 60 * 60 * 24 * 30
)

一些常量

Functions

func GetClaims

func GetClaims() gin.HandlerFunc

JWT中间件,仅通过token获取载荷信息,校验不通过也不报错

func GetToken

func GetToken(ctxt *gin.Context) string

func NeedLogin

func NeedLogin() gin.HandlerFunc

JWT中间件,检查token,校验不通过报错

Types

type JWT

type JWT struct {
	SigningKey []byte
}

JWT 签名结构

func NewJWT

func NewJWT(args ...string) *JWT

新建一个jwt实例

func (*JWT) CreateToken

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

CreateToken 生成一个token

func (*JWT) ParseToken

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

解析Tokne

func (*JWT) RefreshToken

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

更新token

type TokenClaims

type TokenClaims struct {
	ID    int64  `json:"id"`
	Token string `json:"-"`
	jwt.StandardClaims
}

载荷,可以加一些自己需要的信息

Jump to

Keyboard shortcuts

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