token

package
v0.0.0-...-6844190 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type PasetoMaker

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

PasetoMaker is PASETO token maker/manager.

func (*PasetoMaker) CreateToken

func (maker *PasetoMaker) CreateToken(duration time.Duration, userID int64) (string, *Payload, error)

CreateToken create a PASETO based token.

type Payload

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

A Payload contains the payload data of a token.

func NewPayload

func NewPayload(duration time.Duration, userID int64) (*Payload, error)

NewPayload creates a new payload with the user ID and duration.

func (*Payload) Valid

func (p *Payload) Valid() error

Valid checks the expiry-validity of a token

type TokenMaker

type TokenMaker interface {
	// CreateToken creates a new specific token for a user ID and duration
	CreateToken(duration time.Duration, userID int64) (string, *Payload, error)
	// contains filtered or unexported methods
}

A TokenMaker is an interface for managing tokens.

func NewPasetoMaker

func NewPasetoMaker(symmetricKey string) (TokenMaker, error)

NewPasetoMaker creates a new PasetoMaker instance.

Jump to

Keyboard shortcuts

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