middleware

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package middleware exposes HTTP middleware adapters for JWT-only, hybrid, and strict authorization enforcement modes built on top of goAuth.Engine validation.

Guards

  • Guard — auto-selects enforcement mode from Engine config.
  • RequireJWTOnly — stateless JWT verification, no Redis call.
  • RequireStrict — JWT + session store verification.

Each guard reads the Authorization header, calls Engine.Validate, and injects validated claims into the request context.

Architecture boundaries

This package translates HTTP semantics into Engine calls. It does NOT implement authentication logic itself — all decisions are delegated to Engine.Validate.

What this package must NOT do

  • Parse or create JWTs directly (delegates to Engine).
  • Access Redis (Engine handles I/O).
  • Make authorization decisions beyond pass/reject from Engine.Validate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthResultFromContext

func AuthResultFromContext(ctx context.Context) (*goAuth.AuthResult, bool)

AuthResultFromContext extracts the goAuth.AuthResult stored by Guard middleware from the request context.

Docs: docs/middleware.md

func Guard

func Guard(engine *goAuth.Engine, routeMode goAuth.RouteMode) func(http.Handler) http.Handler

Guard returns HTTP middleware that validates access tokens on every request using the provided goAuth.Engine. On success, the goAuth.AuthResult is stored in context for downstream handlers.

Docs: docs/middleware.md, docs/flows.md#validate

func RequireHybrid added in v0.4.0

func RequireHybrid(engine *goAuth.Engine) func(http.Handler) http.Handler

RequireHybrid returns middleware that overrides the validation mode to goAuth.ModeHybrid for the wrapped handler. Hybrid routes validate the JWT statelessly (signature, claims, clock skew — zero Redis); use RequireStrict on routes that need session-backed revocation checks.

Docs: docs/middleware.md, docs/jwt.md

func RequireJWTOnly

func RequireJWTOnly(engine *goAuth.Engine) func(http.Handler) http.Handler

RequireJWTOnly returns middleware that overrides the validation mode to goAuth.ModeJWTOnly for the wrapped handler, skipping Redis entirely.

Docs: docs/middleware.md, docs/jwt.md

func RequireStrict

func RequireStrict(engine *goAuth.Engine) func(http.Handler) http.Handler

RequireStrict returns middleware that overrides the validation mode to goAuth.ModeStrict for the wrapped handler, forcing a Redis session lookup on every request.

Docs: docs/middleware.md, docs/jwt.md

Types

This section is empty.

Jump to

Keyboard shortcuts

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