token

package
v0.0.0-...-f97eb1b Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorExpiredToken = errors.New("token has expired")
	ErrorInvalidToken = errors.New("invalid token")
)

Functions

This section is empty.

Types

type JWTTokenMaker

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

func (*JWTTokenMaker) CreateToken

func (tokenMaker *JWTTokenMaker) CreateToken(userId string, duration time.Duration) (string, *Payload, error)

func (*JWTTokenMaker) VerifyToken

func (tokenMaker *JWTTokenMaker) VerifyToken(token string) (*Payload, error)

type PasetoTokenMaker

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

func (*PasetoTokenMaker) CreateToken

func (tokenMaker *PasetoTokenMaker) CreateToken(userId string, duration time.Duration) (string, *Payload, error)

func (*PasetoTokenMaker) VerifyToken

func (tokenMaker *PasetoTokenMaker) VerifyToken(token string) (*Payload, error)

type Payload

type Payload struct {
	ID        uuid.UUID `json:"id"`
	UserId    uuid.UUID `json:"user_id"`
	IssuedAt  time.Time `json:"issued_at"`
	ExpiredAt time.Time `json:"expired_at"`
	jwt.RegisteredClaims
}

func NewPayload

func NewPayload(userId uuid.UUID, duration time.Duration) (*Payload, error)

func (*Payload) Validate

func (payload *Payload) Validate() error

type TokenMaker

type TokenMaker interface {
	CreateToken(userId string, duration time.Duration) (string, *Payload, error)
	VerifyToken(token string) (*Payload, error)
}

func NewJWTTokenMaker

func NewJWTTokenMaker(secretKey string) (TokenMaker, error)

func NewPasetoTokenMaker

func NewPasetoTokenMaker(symmetricKey string) (TokenMaker, error)

Jump to

Keyboard shortcuts

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