token

package module
v0.0.0-...-3a28f6d Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

README

go-pkg token

介绍

jwt 认证使用的token解析与签名包

软件架构
安装教程
go get -u gitee.com/lyhuilin/pkg/token
使用说明

go get gitee.com/lyhuilin/pkg

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrMissingHeader means the `Authorization`header was empty
	ErrMissingHeader = errors.New("the length of the `Authorization` header is zero.")
)

Functions

func GetJwtSecret

func GetJwtSecret() string

func SetJwtSecret

func SetJwtSecret(jwtSecret string)

func Sign

func Sign(ctx *gin.Context, c Context, secret string) (tokenString string, err error)

sign sings the context with the specified secret

Types

type Context

type Context struct {
	// 用户id
	ID uint64
	// 用户uuid
	UUID string
	// 用户名
	Username string
	// SafeCode string
	// 过期日期时间戳 time unix
	Expiry int64
}

Context is the context of the JSON web token

func Parse

func Parse(tokenString string, secret string) (*Context, error)

parse validates the token with the specified secret, and returns the context if the token was valid

func ParseRequest

func ParseRequest(c *gin.Context) (*Context, error)

parseRequest gets the token from the header and pass it to the parse function to parses the token.

Jump to

Keyboard shortcuts

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