jwt

package
v1.1.31 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const JWT_PAYLOAD key = "jwt-payload"

Variables

View Source
var (
	ErrInvalidToken = errors.New("token is invalid")
	ErrExpiredToken = errors.New("token has expired")
)

Functions

func AppendRequestCtx

func AppendRequestCtx(r *http.Request, ctxKey key, input interface{}) context.Context

func CheckIsAuthorize

func CheckIsAuthorize(r *http.Request, accessId uuid.UUID)

Types

type JWT

type JWT interface {
	CreateToken(tokenType string, params PayloadParams, duration time.Duration) (string, *Payload, error)
	VerifyToken(token string) (*Payload, error)
}

func NewJWTMaker

func NewJWTMaker(config *common_utils.BaseConfig) (JWT, error)

type JWTMaker added in v1.0.13

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

func (*JWTMaker) CreateToken added in v1.0.13

func (m *JWTMaker) CreateToken(tokenType string, params PayloadParams, duration time.Duration) (string, *Payload, error)

func (*JWTMaker) VerifyToken added in v1.0.13

func (m *JWTMaker) VerifyToken(token string) (*Payload, error)

type Payload

type Payload struct {
	jwt.RegisteredClaims
	ID        uuid.UUID `json:"id"`
	UserId    uuid.UUID `json:"userId"`
	Email     string    `json:"email"`
	Role      string    `json:"role"`
	Status    string    `json:"status"`
	TokenType string    `json:"tokenType"`
	IssuedAt  time.Time `json:"issuedAt"`
	ExpiredAt time.Time `json:"expiredAt"`
}

func GetRequestCtx

func GetRequestCtx(r *http.Request, ctxKey key) *Payload

func NewPayload

func NewPayload(params PayloadParams, duration time.Duration) *Payload

func (*Payload) Valid

func (payload *Payload) Valid() error

type PayloadParams

type PayloadParams struct {
	UserId uuid.UUID `json:"id"`
	Email  string    `json:"email"`
	Role   string    `json:"role"`
	Status string    `json:"status"`
}

Jump to

Keyboard shortcuts

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