middleware

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const WbtSessionCookie = "wbt_session"

WbtSessionCookie is the name of the httpOnly browser session cookie. Must stay in sync with handler.WbtSessionCookie — they share the same value.

Variables

This section is empty.

Functions

func APIKeyMiddleware

func APIKeyMiddleware(apiKey string) echo.MiddlewareFunc

APIKeyMiddleware returns an Echo middleware that validates the caller's identity. It accepts two authentication paths in priority order:

  1. X-API-Key header — used by MCP clients, CLI tools, and curl.
  2. wbt_session cookie — used by the React SPA (httpOnly, Secure, SameSite=Strict).

On success, an auth.Authorized capability token is stored in the Echo context under auth.ContextKey. Downstream handlers may retrieve it via auth.FromContext. The expected key is passed at construction time so it is read from env once at startup.

func CORSMiddleware

func CORSMiddleware(allowedOrigins string) echo.MiddlewareFunc

CORSMiddleware returns an Echo CORS middleware. allowedOrigins is a comma-separated list of explicit origins. AllowCredentials is set to true so that the browser can send the wbt_session httpOnly cookie in cross-origin requests.

IMPORTANT: allowedOrigins must not be "*" or empty — wildcard origins are incompatible with AllowCredentials=true and browsers reject such responses. This function panics at startup when an unsafe value is detected to prevent silent misconfiguration in production.

Types

This section is empty.

Jump to

Keyboard shortcuts

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