jwt

package
v0.0.0-...-357760b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const TokenExpireDuration = time.Hour * 2

TokenExpireDuration Token过期时间

Variables

This section is empty.

Functions

func GenToken

func GenToken(userID int64, username string) (string, error)

GenToken 生成一个 Token

func RefreshToken

func RefreshToken(aToken, rToken string) (newAToken, newRToken string, err error)

RefreshToken 刷新 Access Token 的接口 return (newAToken, newRToken string, err error) 如果我们邀请能够续token, 那就每次请求都返回一个新的Refreshtoken,这样就会和循环自动续上refreshtoken的有效期 如果我们希望refresh到期强制重新登录,不希望能够续token的话,可以只返回新的Accress Token,refreshtoken返回旧的

Types

type MyClaims

type MyClaims struct {
	UserID   int64  `json:"user_id"`
	Username string `json:"username"`
	jwt.StandardClaims
}

MyClaims 自定义声明结构体并内嵌 jwt.StandarCMyClaims jwt 包自带的 jwt.StandardClaims 只包含了官方字段 我们这里需要额外记录一个 username 字段,所以要自定义结构体 如果想要保存更多的信息,都可以添加到这个结构体中

func ParseToken

func ParseToken(tokenString string) (*MyClaims, error)

ParseToken 解析 Token

Jump to

Keyboard shortcuts

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