jwt

package
v0.0.0-...-4f2055d Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenExpired     = errors.New("Token is expired")
	TokenNotValidYet = errors.New("Token not active yet")
	TokenMalformed   = errors.New("That's not even a token")
	TokenInvalid     = errors.New("Couldn't handle this token:")
)

Functions

func GetUserName

func GetUserName(c *gin.Context, config JWTConfig) string

func GetUserRole

func GetUserRole(c *gin.Context, config JWTConfig) uint

Types

type JWT

type JWT struct {
	SigningKey  []byte
	ExpiresTime int64
	BufferTime  int64
	Issuer      string
}

func NewJWT

func NewJWT(config JWTConfig) *JWT

func (*JWT) CreateClaims

func (j *JWT) CreateClaims(baseClaims JWTBaseClaims) JWTCustomClaims

func (*JWT) CreateToken

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

创建一个token

func (*JWT) ParseToken

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

解析 token

type JWTBaseClaims

type JWTBaseClaims struct {
	Username string
	Role     uint
}

type JWTConfig

type JWTConfig struct {
	SigningKey  string `mapstructure:"signing-key" json:"signingKey" yaml:"signing-key"`    // jwt签名
	ExpiresTime int64  `mapstructure:"expires-time" json:"expiresTime" yaml:"expires-time"` // 过期时间
	BufferTime  int64  `mapstructure:"buffer-time" json:"bufferTime" yaml:"buffer-time"`    // 缓冲时间
	Issuer      string `mapstructure:"issuer" json:"issuer" yaml:"issuer"`                  // 签发者
}

type JWTCustomClaims

type JWTCustomClaims struct {
	JWTBaseClaims
	BufferTime int64
	jwt.StandardClaims
}

func GetClaims

func GetClaims(c *gin.Context, config JWTConfig) (*JWTCustomClaims, error)

Jump to

Keyboard shortcuts

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