jwtutils

package
v0.0.0-...-cfa74d8 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const UserClaimsFlag = "userClaims"
View Source
const UserJwtPayload = "userPayload"

Variables

View Source
var (
	ErrJwtNeedToRefresh = errors.New("token需要刷新")
)

Functions

func CreateHs256Jwt

func CreateHs256Jwt(claims Claims, secret string) (string, error)

CreateHs256Jwt @Date 2023-01-20 20:35:38 @Param signKey string @Param userId string @Param issuer string @Param expired time.Duration @Return string @Return error @Method @Description: 使用HMCA256对称加密算法创建一个token

func SetConfig

func SetConfig(cfg *config.JwtConfig)

Types

type Claims

type Claims struct {
	UserClaims
	jwt.RegisteredClaims
}

Claims @Date 2023-01-20 20:10:39 @Description: 自定义Token声明

func CreateJwtClaims

func CreateJwtClaims(userClaims UserClaims, issuer string, expired time.Duration) Claims

func ParseHs256Jwt

func ParseHs256Jwt(jwtStr string, secret string) (Claims, error)

ParseHs256Jwt @Date 2023-01-20 22:03:46 @Param jwtStr string @Param secret string @Return Claims @Return error @Method @Description: 解析一个HS256签名的JWT

func ToJwtClaims

func ToJwtClaims(ctx *gin.Context) (*Claims, error)

type UserClaims

type UserClaims struct {
	UserId   uint   `json:"userId"`
	UserUUID string `json:"userUUID"`
}

Jump to

Keyboard shortcuts

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