authrpc

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package authrpc provides the legacy fail-closed JSON-RPC authorization middleware.

Deprecated: use github.com/faustbrian/go-authorization/v3/adapters/jsonrpc. This package remains supported for the longer of 180 days after successor public availability and two subsequently published stable root-module minor releases.

Index

Constants

View Source
const CodeForbidden = -32001

CodeForbidden is the application JSON-RPC forbidden code (-32001).

Variables

View Source
var (
	// ErrNilAuthorizer preserves the direct adapter error identity for errors.Is.
	ErrNilAuthorizer = adapter.ErrNilAuthorizer
	// ErrNilRequestMapper preserves the direct adapter error identity for errors.Is.
	ErrNilRequestMapper = adapter.ErrNilRequestMapper
)

Functions

func DecisionFromContext

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

DecisionFromContext returns the attached decision by value; its slices remain shared.

func NewMiddleware

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

NewMiddleware delegates to the direct fail-closed adapter, retaining this facade type/options. Literal nil dependencies fail; typed-nil/custom callback panics are not handled here. See adapters/jsonrpc for response/context ownership.

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 from trusted caller-mapped input. Implementations must cooperate with ctx and support concurrent reuse; this seam performs no authentication.

type DeniedError

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

DeniedError maps a non-allow decision; custom output owns privacy and byte policy.

type ErrorMapper

type ErrorMapper func(error) *jsonrpc.Error

ErrorMapper maps raw local causes; do not expose secrets in JSON-RPC data/messages.

type Option

type Option func(*options)

Option configures construction synchronously; nil/custom options may panic.

func WithDeniedError

func WithDeniedError(mapper DeniedError) Option

WithDeniedError selects denial mapping; nil retains the bounded forbidden default.

func WithErrorMapper

func WithErrorMapper(mapper ErrorMapper) Option

WithErrorMapper selects failure mapping; nil retains the generic internal-error default.

type RequestMapper

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

RequestMapper maps borrowed raw parameters/context to trusted policy facts; it must be synchronous, cooperative and safe for concurrent handler reuse.

Jump to

Keyboard shortcuts

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