authorizationhttp

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package authorizationhttp provides fail-closed net/http authorization integration. NewHandler grants only a valid explicit Allow; it does not verify credentials or fetch resource/tenant facts. Authorizers, mappers, handlers and options are borrowed synchronous code; panics/blocking calls are not contained. Default responses contain no cause text, but context helpers expose raw local failures/decision slices. No background worker or handler shutdown is owned.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilAuthorizer reports that NewHandler received no authorizer.
	ErrNilAuthorizer = errors.New("HTTP authorization authorizer is nil")
	// ErrNilRequestMapper reports that NewHandler received no request mapper.
	ErrNilRequestMapper = errors.New("HTTP authorization request mapper is nil")
	// ErrNilNextHandler reports that NewHandler received no downstream handler.
	ErrNilNextHandler = errors.New("HTTP authorization next handler is nil")
)

Functions

func DecisionFromContext

func DecisionFromContext(ctx context.Context) (authorization.Decision, bool)

DecisionFromContext returns the decision attached for denied or allowed downstream handling.

func ErrorFromContext

func ErrorFromContext(ctx context.Context) (error, bool)

ErrorFromContext returns the local failure attached for a configured error handler.

func NewHandler

func NewHandler(
	authorizer Authorizer,
	mapper RequestMapper,
	next http.Handler,
	handlerOptions ...Option,
) (http.Handler, error)

NewHandler constructs fail-closed authorization middleware around next. Only Allow reaches next; denial/failure handlers receive local context state. Dependencies are literal-nil checked only; typed nils/custom options can panic. Concurrent requests require reusable borrowed callbacks/handlers. Context values contain shared decision slices/raw errors, not sanitized public diagnostics.

Types

type Authorizer

type Authorizer interface {
	// Decide returns a valid outcome or error; map errors to failure, never allow.
	Decide(context.Context, authorization.Request) (authorization.Decision, error)
}

Authorizer decides whether a mapped HTTP request may reach its downstream handler.

type Option

type Option func(*options)

Option configures HTTP authorization failure handling.

func WithDeniedHandler

func WithDeniedHandler(handler http.Handler) Option

WithDeniedHandler replaces the handler used for valid non-allow decisions. A nil handler leaves the default HTTP 403 response unchanged.

func WithErrorHandler

func WithErrorHandler(handler http.Handler) Option

WithErrorHandler replaces the handler used for mapping, evaluation, and invalid-outcome failures. A nil handler leaves the default HTTP 500 response unchanged.

type RequestMapper

type RequestMapper func(*http.Request) (authorization.Request, error)

RequestMapper maps an HTTP request to the transport-neutral authorization request.

Jump to

Keyboard shortcuts

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