authware

package
v0.0.0-...-6cb8ef5 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultContextKey     = "secret-user-data"
	DefaultAuthContextKey = "auth-token"
)

Variables

View Source
var ConfigDefault = Config{
	Next:                nil,
	Forbidden:           nil,
	AuthContextKey:      DefaultAuthContextKey,
	NamespaceContextKey: DefaultContextKey,
	CacheStorage:        memory.New(),
}

ConfigDefault is the default config

Functions

func New

func New(authConfig Config) fiber.Handler

New creates a new middleware handler

Types

type Config

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

	// NamespaceChecker defines a function that checks user and returns its ID, in case user not found, return 0
	//
	// Required. Default: nil
	NamespaceChecker TokenChecker

	// CheckerError defines the response body for unauthorized responses.
	// By default, it will return with a 401 CheckerError
	//
	// Optional. Default: nil
	CheckerError fiber.Handler

	// Forbidden defines the response body for unauthorized responses.
	// By default it will return with a 403 Forbidden
	//
	// Optional. Default: nil
	Forbidden fiber.Handler

	// AuthContextKey is the key to look out the auth name in Locals
	//
	// Optional. Default: "auth-token"
	AuthContextKey string

	// NamespaceContextKey is the key to store the userID in Locals
	//
	// Optional. Default: "secret-user-id"
	NamespaceContextKey string

	// CacheStorage is the storage used to store users in cache, to preventing searching them multiple times
	//
	// Optional. Default: memory
	CacheStorage fiber.Storage
}

Config defines all configs needed by the middleware

type TokenChecker

type TokenChecker func(authToken string) (*dtos.CustomerDTO, error)

Config defines the config for middleware.

Jump to

Keyboard shortcuts

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