jwt

package
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Issuer = "xuanwu wan199406@gmail.com"
)

Variables

View Source
var (
	SigningMethod = jwtv4.SigningMethodHS256
)

Functions

func AuthPlugin

func AuthPlugin(handler middleware.Handler) middleware.Handler

AuthPlugin get jwt claims from context and put CurrentUser into it.

func CreateToken

func CreateToken(secretKey []byte, username, email, phoneNumber string, extraInfo map[string]interface{}) (string, error)

func NewJWTFunc

func NewJWTFunc(secretKey []byte) func(token *jwtv4.Token) (interface{}, error)

func NewWhiteListMatcher

func NewWhiteListMatcher(whiteList map[string]bool) selector.MatchFunc

Types

type CurrentUser

type CurrentUser struct {
	Username    string                 `json:"username"`
	Email       string                 `json:"email"`
	PhoneNumber string                 `json:"phoneNumber"`
	ExtraInfo   map[string]interface{} `json:"extraInfo"`
}

func FromContext

func FromContext(ctx context.Context) (CurrentUser, error)

type CustomClaims

type CustomClaims struct {
	User CurrentUser `json:"user"`
	jwtv4.RegisteredClaims
}

Jump to

Keyboard shortcuts

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