pasetoware

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExpiredToken  = errors.New("token has expired")
	ErrMissingToken  = errors.New("missing PASETO token")
	ErrInvalidToken  = errors.New("invalid PASETO token")
	ErrDataUnmarshal = errors.New("can't unmarshal token data to Payload type")

	TokenAudience = "gofiber.gophers"
	TokenSubject  = "user-token"
	TokenPrefix   = "Bearer"
)
View Source
var ConfigDefault = Config{
	Next:           nil,
	SuccessHandler: nil,
	ErrorHandler:   nil,
	Tokener:        NewTokener(),
}

ConfigDefault is the default config

Functions

func New

func New(authConfigs ...Config) fiber.Handler

New PASETO middleware, returns a handler that takes a token in selected lookup param and in case token is valid it saves the decrypted token on ctx.Locals, take a look on Config to know more configuration options

Types

type Config

type Config struct {
	// Filter defines a function to skip middleware.
	// Optional. Default: nil
	Next func(*fiber.Ctx) bool

	// SuccessHandler defines a function which is executed for a valid token.
	// Optional. Default: c.Next()
	SuccessHandler fiber.Handler

	// ErrorHandler defines a function which is executed for an invalid token.
	// It may be used to define a custom PASETO error.
	// Optional. Default: 401 Invalid or expired PASETO
	ErrorHandler fiber.ErrorHandler

	Tokener *Tokener

	PayloadKeys []string
}

Config defines the config for PASETO middleware

type Tokener

type Tokener struct {
	TokenPrivateKey paseto.V4AsymmetricSecretKey
	TokenPublicKey  paseto.V4AsymmetricPublicKey
}

func NewTokener

func NewTokener() *Tokener

func (*Tokener) GenerateToken

func (t *Tokener) GenerateToken(m map[string]string, expiration time.Duration) string

func (*Tokener) ParseToken

func (t *Tokener) ParseToken(token string) (*paseto.Token, error)

Jump to

Keyboard shortcuts

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