middlewares

package
v1.331.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequireAuthOrAPIKeyMiddlewareID        = "requireAuthOrAPIKey"
	RequireInternalAdminAPIKeyMiddlewareID = "requireInternalAdminAPIKey"
	RequireInternalAdminOrAuthMiddlewareID = "requireInternalAdminOrAuth"
)
View Source
const ValidatedInputKey validatedInputKeyType = "validatedInput"

Variables

This section is empty.

Functions

func APIKeyPrincipal

func APIKeyPrincipal(e *core.RequestEvent) (*core.Record, *apierror.APIError)

APIKeyPrincipal resolves the Credimi-Api-Key of the request, accepting the same internal-admin and user-scoped keys as RequireInternalAdminOrAuth. It returns a nil principal when the request carries no key.

func DynamicValidateInputByType

func DynamicValidateInputByType(inputType reflect.Type) func(e *core.RequestEvent) error

func ErrorHandlingMiddleware

func ErrorHandlingMiddleware(e *core.RequestEvent) error

ErrorHandlingMiddleware renders every error of a Credimi route group as an apierror.Response, and records server errors (5xx) as exceptions on the request span.

Handlers return *apierror.APIError. PocketBase errors (apis.New*Error, e.BadRequestError and the other RequestEvent helpers) keep their status, so a stray one never turns into a 500; any other error is a 500.

func OptionalAuthOrAPIKey

func OptionalAuthOrAPIKey() *hook.Handler[*core.RequestEvent]

OptionalAuthOrAPIKey authenticates a Credimi-Api-Key when present, but does not block requests that provide no credentials.

func RequireAuthOrAPIKey

func RequireAuthOrAPIKey() *hook.Handler[*core.RequestEvent]

RequireAuthOrAPIKey accepts either a Bearer token or a user-scoped API key.

func RequireCachedAPIKey added in v1.324.0

func RequireCachedAPIKey() *hook.Handler[*core.RequestEvent]

RequireCachedAPIKey accepts the same internal-admin and user-scoped keys as RequireInternalAdminOrAuth, for routes called every few seconds. A key is bcrypt-verified once per process; later requests reload its api_keys record by ID and check revocation, expiry, owner and scope again, so a revoked key is refused on its next request.

func RequireInternalAdminAPIKey

func RequireInternalAdminAPIKey() *hook.Handler[*core.RequestEvent]

RequireInternalAdminAPIKey requires an internal-admin API key.

func RequireInternalAdminOrAuth

func RequireInternalAdminOrAuth() *hook.Handler[*core.RequestEvent]

RequireInternalAdminOrAuth accepts either an internal-admin API key or a user auth context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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