middlerware

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: MIT Imports: 7 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 JWTAuth

func JWTAuth() gin.HandlerFunc

Types

type BaseClaims

type BaseClaims struct {
	ID       int
	UserName string
}

type CustomClaims

type CustomClaims struct {
	BaseClaims
	BufferTime int64
	jwt.StandardClaims
}

Custom claims structure

func GetClaims

func GetClaims(c *gin.Context) (*CustomClaims, error)

func GetUserInfo

func GetUserInfo(c *gin.Context) *CustomClaims

Get the user roles parsed from jwt from the Context of Gin

type JWT

type JWT struct {
	SigningKey []byte
}

func NewJWT

func NewJWT() *JWT

func (*JWT) CreateClaims

func (j *JWT) CreateClaims(baseClaims BaseClaims) CustomClaims

func (*JWT) CreateToken

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

create a token

func (*JWT) CreateTokenByOldToken

func (j *JWT) CreateTokenByOldToken(oldToken string, claims CustomClaims) (string, error)

Replacing old token with new token using merging and origin-pull to avoid concurrency problems

func (*JWT) ParseToken

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

Jump to

Keyboard shortcuts

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