simplemiddleware

package module
v0.0.0-...-120b54f Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: MIT Imports: 7 Imported by: 4

Documentation

Index

Constants

View Source
const (
	AuthHeader  = "Authorization"
	ClaimUserId = "uid"
	ClaimGrant  = "grant"
)

Variables

View Source
var (
	ErrClaimDataType  = errors.New("claim is not a string")
	ErrGrantDataType  = errors.New("grant claim is not a string")
	ErrUserIdDataType = errors.New("user ID claim is not a string")
)
View Source
var (
	// common errors
	ErrInvalidBearerToken = errors.New("invalid or missing bearer token")
)
View Source
var SetAuthPublicKey = func(pubKey []byte) {
	publicAuthKey = pubKey
}
View Source
var SetClaimGrant = func(grant string) {
	claimGrant = grant
}
View Source
var SetClaimUserId = func(id string) {
	claimUserId = id
}
View Source
var SetErrFunc = func(fn ErrFunc) {
	authenticator.SetErrFunc(fn)
}
View Source
var SetKeyFunc = func(fn KeyFunc) {
	authenticator.SetKeyFunc(fn)
}

Functions

func Authorize

func Authorize(handler server.Handler) server.Handler

Types

type ErrFunc

type ErrFunc func(w http.ResponseWriter, err error)

ErrFunc represets a callback function for handling errors when validating requests.

type KeyFunc

type KeyFunc func(token *Token) ([]byte, error)

KeyFunc is a function for returning the key of the JSON Web Token.

type Middleware

type Middleware interface {
	// Extract extracts a bearer token from a request.
	Extract(r *http.Request) (tkn string)

	// Handle wraps the given handler for validating a request via a JWT.
	Handle(handler http.HandlerFunc) http.HandlerFunc

	// SetErrFunc sets the function for handling errors during  JWT
	// validation.
	SetErrFunc(fn ErrFunc)

	// SetKeyFunc sets the function for retrieving the JWT's public key.
	SetKeyFunc(fn KeyFunc)
}

Middleware represents an interface to a middleware object.

func New

func New(header string, keyFunc KeyFunc, errFunc ErrFunc) Middleware

New returns a new Middleware object.

type Token

type Token jwt.Token

Token represents a JSON Web Token.

Jump to

Keyboard shortcuts

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