authcookie

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Next:                nil,
	Authorizer:          nil,
	Unauthorized:        nil,
	JWTSecretKey:        nil,
	UserCtxName:         types.UserCtxName,
	HeaderCookieName:    "he",
	PayloadCookieName:   "pa",
	SignatureCookieName: "si",
}

ConfigDefault is the default config

Functions

func New

func New(config 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(c *fiber.Ctx) bool

	// Realm is a string to define realm attribute of BasicAuth.
	// the realm identifies the system to authenticate against
	// and can be used by clients to save credentials
	//
	// Optional. Default: "Restricted".
	Realm string

	// Authorizer defines a function you can pass
	// to check the credentials however you want.
	// It will be called with a JWT token
	// and is expected to return user claim or error to indicate
	// that the credentials were approved or not.
	//
	// Optional. Default: nil.
	Authorizer func(token string) (jwt.MapClaims, error)

	// Unauthorized defines the response body for unauthorized responses.
	// By default it will return with a 401 Unauthorized and the correct WWW-Auth header
	//
	// Optional. Default: nil
	Unauthorized fiber.Handler

	// JWTSecretKey is the key to validate JWT token
	//
	// Optional. Default: nil
	JWTSecretKey []byte

	// UserCtxName is the key to store the user context in Locals
	//
	// Optional. Default: "user"
	UserCtxName string

	// HeaderCookieName is the name of cookie keeping JWT header
	//
	// Optional. Default: "he"
	HeaderCookieName string

	// PayloadCookieName is the name of cookie keeping JWT payload
	//
	// Optional. Default: "pa"
	PayloadCookieName string

	// SignatureCookieName is the name of cookie keeping JWT signature
	//
	// Optional. Default: "si"
	SignatureCookieName string
}

Config defines the config for middleware.

Jump to

Keyboard shortcuts

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