ginxjwt

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionInvalid  = errors.New("session invalid")
	ErrNoAuthorization = errors.New("no authorization")
	ErrTokenInvalid    = errors.New("token invalid")
)
View Source
var (
	JWTKey   = []byte("k6CswdUm77WKcbM68UQUuxVsHSpTCwgK")
	RfJWTKey = []byte("k6CswdUm77WKcbM68UQUuxVsHSpTCwgA")
)

Functions

This section is empty.

Types

type Handler

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

func (*Handler) CheckToken

func (h *Handler) CheckToken(ctx *gin.Context) (JwtClaims, error)

CheckToken check if the token is valid and token is not logged out

func (*Handler) ClearToken

func (h *Handler) ClearToken(ctx *gin.Context) error

ClearToken add ssid to redis to mark token as logged out

func (*Handler) ExtractToken

func (h *Handler) ExtractToken(ctx *gin.Context) (JwtClaims, error)

ExtractToken extracts the token from auth header

func (*Handler) GenToken

func (h *Handler) GenToken(ctx *gin.Context, uid int64) (string, string, error)

GenToken will generate jwtToken and refreshToken

func (*Handler) RefreshToken

func (h *Handler) RefreshToken(ctx *gin.Context) (string, error)

type JWT

type JWT interface {
	GenToken(ctx *gin.Context, uid int64) (string, string, error)
	ExtractToken(ctx *gin.Context) (JwtClaims, error)
	ClearToken(ctx *gin.Context) error
	CheckToken(ctx *gin.Context) (JwtClaims, error)
	RefreshToken(ctx *gin.Context) (string, error)
}

func NewJWT

func NewJWT(client redis.Cmdable) JWT

type JwtClaims

type JwtClaims struct {
	Uid int64

	jwt.RegisteredClaims
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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