tokens

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 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")
View Source
var ErrInvalidToken = errors.New("token is invalid")

Functions

This section is empty.

Types

type PasetoBuilder

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

func (*PasetoBuilder) CreateToken

func (builder *PasetoBuilder) CreateToken(p PayloadData, duration time.Duration) (string, *Payload, error)

func (*PasetoBuilder) VerifyToken

func (builder *PasetoBuilder) VerifyToken(token string) (*Payload, error)

Verifys token integrity and expiration time

type Payload

type Payload struct {
	Id        uuid.UUID   `json:"id,omitempty"`
	IssuedAt  time.Time   `json:"iat,omitempty"`
	ExpiresAt time.Time   `json:"expires,omitempty"`
	Payload   PayloadData `json:"payload,omitempty"`
}

func NewPayload

func NewPayload(p PayloadData, duration time.Duration) (*Payload, error)

func (*Payload) Valid

func (payload *Payload) Valid() error

type PayloadData

type PayloadData struct {
	UserID    uuid.UUID `json:"user_id,omitempty"`
	UserEmail string    `json:"user_email,omitempty"`

	RecoveryCode     string `json:"recovery_code,omitempty"`
	DeletionCode     string `json:"deletion_code,omitempty"`
	VerificationCode string `json:"email_verification_code,omitempty"`

	AllowIP     string `json:"allow_ip,omitempty"`
	AllowIPCode string `json:"allow_ip_code,omitempty"`
}

type TokenBuilder

type TokenBuilder interface {
	// Create Token if token for specific duration
	CreateToken(data PayloadData, duration time.Duration) (string, *Payload, error)

	// Validates token integrity and expiration time
	VerifyToken(token string) (*Payload, error)
}

TokenBuilder is an interface for managing tokens

func NewPasetoBuilder

func NewPasetoBuilder(symmetricKey string) (TokenBuilder, error)

Jump to

Keyboard shortcuts

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