middleware

package
v0.0.0-...-b25413d Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClaimsKey

func ClaimsKey() any

ClaimsKey returns the context key used to store JWT claims.

func ExtractTenant

func ExtractTenant(api huma.API) func(huma.Context, func(huma.Context))

claimsKey is the context key used by the auth middleware to store JWT claims. This mirrors the implementation there so that this middleware can read them. ExtractTenant obtains the tenant ID from the X-Tenant-ID header or JWT claim "tid". A missing tenant results in 400.

func JWT

func JWT(api huma.API, secret string) func(huma.Context, func(huma.Context))

JWT returns middleware that validates a bearer token signed with the given secret.

func MetricsMW

func MetricsMW(ctx huma.Context, next func(huma.Context))

MetricsMW records API request metrics.

func RBAC

func RBAC(enf *casbin.Enforcer, resolve RoleResolver) func(huma.Context, func(huma.Context))

RBAC enforces access where either the user or any of their roles is allowed.

func UserFromContext

func UserFromContext(ctx context.Context) string

UserFromContext returns the user subject stored in the context.

func UserKey

func UserKey() any

UserKey returns the context key used to store the user subject.

Types

type RoleResolver

type RoleResolver func(ctx context.Context, user string) ([]string, error)

Jump to

Keyboard shortcuts

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