authorizationjsonrpc

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package authorizationjsonrpc provides fail-closed JSON-RPC authorization middleware.

Index

Constants

View Source
const CodeForbidden = -32001

CodeForbidden is the bounded JSON-RPC server error code for authorization denial.

Variables

View Source
var (
	// ErrNilAuthorizer reports that NewMiddleware received no authorizer.
	ErrNilAuthorizer = errors.New("JSON-RPC authorization authorizer is nil")
	// ErrNilRequestMapper reports that NewMiddleware received no request mapper.
	ErrNilRequestMapper = errors.New("JSON-RPC authorization request mapper is nil")
)

Functions

func DecisionFromContext

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

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

func NewMiddleware

func NewMiddleware(
	authorizer Authorizer,
	mapper RequestMapper,
	middlewareOptions ...Option,
) (jsonrpc.Middleware, error)

NewMiddleware constructs fail-closed JSON-RPC authorization middleware. Only Allow reaches the next handler; nil custom-mapper results are contained as internal errors.

Types

type Authorizer

type Authorizer interface {
	Decide(context.Context, authorization.Request) (authorization.Decision, error)
}

Authorizer decides whether a mapped JSON-RPC request may reach its method handler.

type DeniedError

type DeniedError func(authorization.Decision) *jsonrpc.Error

DeniedError maps a valid non-allow decision to a JSON-RPC error.

type ErrorMapper

type ErrorMapper func(error) *jsonrpc.Error

ErrorMapper maps request-mapping and evaluation failures to JSON-RPC errors.

type Option

type Option func(*options)

Option configures JSON-RPC authorization failure mapping.

func WithDeniedError

func WithDeniedError(mapper DeniedError) Option

WithDeniedError replaces the mapper for valid non-allow decisions. A nil mapper leaves the default forbidden response unchanged.

func WithErrorMapper

func WithErrorMapper(mapper ErrorMapper) Option

WithErrorMapper replaces the mapper for mapping, evaluation, and invalid-outcome failures. A nil mapper leaves the default internal-error response unchanged.

type RequestMapper

type RequestMapper func(context.Context, json.RawMessage) (authorization.Request, error)

RequestMapper maps JSON-RPC context and raw parameters to an authorization request.

Jump to

Keyboard shortcuts

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