jwt

package
v0.0.0-...-4c38643 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUserId

func GetUserId(ctx context.Context) int64

GetUserId try get userId from jwt context

func WithToken

func WithToken(ctx context.Context, info *ClientInfo) context.Context

WithToken save client info to context

Types

type ClientInfo

type ClientInfo struct {
	UserId     int64
	DeviceId   string
	ClientType string
	Domain     string
	AppVersion int32
}

func FromJwtContext

func FromJwtContext(ctx context.Context) ClientInfo

FromJwtContext extract client info from jwt context

type TokenDetails

type TokenDetails struct {
	AccessToken  string
	RefreshToken string
	AccessUuid   string
	RefreshUuid  string
	AtExpires    int64
	RtExpires    int64
}

type TokenGenerate

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

func NewTokenGenerate

func NewTokenGenerate(accessSecret, refreshSecret string) *TokenGenerate

NewTokenGenerate create TokenGenerate example:

func (*TokenGenerate) CreateToken

func (t *TokenGenerate) CreateToken(info ClientInfo) (*TokenDetails, error)

func (*TokenGenerate) GetClaimsFromJWTToken

func (t *TokenGenerate) GetClaimsFromJWTToken(tokenStr string, isRefreshToken bool) (jwt.MapClaims, error)

func (*TokenGenerate) ParseToken

func (t *TokenGenerate) ParseToken(tokenStr string, isRefreshToken bool) (*ClientInfo, *TokenDetails, error)

func (*TokenGenerate) TokenIsValid

func (t *TokenGenerate) TokenIsValid(tokenStr string, isRefreshToken bool) error

Jump to

Keyboard shortcuts

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