token

package
v0.0.0-...-a2c21a8 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JwtWithAuthInfo

func JwtWithAuthInfo(jt *Token) middleware.Middleware

func WithLoginContext

func WithLoginContext(ctx context.Context, loginInfo *CustomClaims) context.Context

Types

type CustomClaims

type CustomClaims struct {
	UserName string `json:"user_name"`
	UserID   int64  `json:"uid"`
	Role     string `json:"role"`
	jwt.StandardClaims
}

CustomClaims 自定义的 metadata在加密后作为 JWT 的第二部分返回给客户端

func FormLoginContext

func FormLoginContext(ctx context.Context) *CustomClaims

type LoginInfoKey

type LoginInfoKey struct{}

type Token

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

Token jwt

func New

func New(privateKeyByte, publicKeyByte []byte) (*Token, error)

func NewPublic

func NewPublic(publicKeyByte []byte) (*Token, error)

func (*Token) Decode

func (srv *Token) Decode(tokenStr string) (*CustomClaims, error)

Decode 解码

func (*Token) Encode

func (srv *Token) Encode(userName string, userId int64, role string, expireTime int64) (string, error)

Encode 将 User 用户信息加密为 JWT 字符串 expireTime := time.Now().Add(time.Hour * 24 * 3).Unix() 三天后过期

Jump to

Keyboard shortcuts

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