jwt

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 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(params PayloadParams, duration time.Duration) (string, *Payload, error)
	VerifyToken(token string) (*Payload, error)
}

type JwtMaker

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

func NewJWTMaker

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

func (*JwtMaker) CreateToken

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

func (*JwtMaker) VerifyToken

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

type Payload

type Payload struct {
	jwt.Claims
	ID        uuid.UUID `json:"id"`
	UserId    uuid.UUID `json:"userId"`
	Email     string    `json:"email"`
	Role      string    `json:"role"`
	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"`
}

Jump to

Keyboard shortcuts

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