Documentation
¶
Overview ¶
Package auth provides authentication middleware and context helpers.
Index ¶
- Constants
- func AuthCheckHandler() http.HandlerFunc
- func AuthenticateStaticRequest(r *http.Request, apiKey, defaultTenant string) (string, bool)
- func ClearSessionCookie(r *http.Request) *http.Cookie
- func ExtractTenantHeader(header string) string
- func KeyStoreMiddleware(lookup KeyStoreAuthFunc) func(http.Handler) http.Handler
- func NewSessionCookie(r *http.Request, apiKey, tenantID string, ttl time.Duration) (*http.Cookie, error)
- func ParseBearerToken(header string) string
- func StaticKeyMatches(apiKey, candidate string) bool
- func StaticKeyMiddleware(apiKey, defaultTenant string) func(http.Handler) http.Handler
- func TenantID(ctx context.Context) string
- func WithTenantID(ctx context.Context, tenantID string) context.Context
- type KeyStoreAuthFunc
Constants ¶
const SessionCookieName = "bench_session"
Variables ¶
This section is empty.
Functions ¶
func AuthCheckHandler ¶
func AuthCheckHandler() http.HandlerFunc
AuthCheckHandler returns 200 with X-Bench-Tenant for valid tokens (forwardAuth target).
func AuthenticateStaticRequest ¶ added in v0.5.46
AuthenticateStaticRequest validates either a Bearer API key or a signed browser session cookie and returns the authenticated tenant.
func ClearSessionCookie ¶ added in v0.5.46
ClearSessionCookie returns a Set-Cookie value that expires the browser session.
func ExtractTenantHeader ¶
ExtractTenantHeader reads X-Bench-Tenant for downstream use (e.g., after forwardAuth).
func KeyStoreMiddleware ¶
func KeyStoreMiddleware(lookup KeyStoreAuthFunc) func(http.Handler) http.Handler
KeyStoreMiddleware authenticates requests using a database-backed key store.
func NewSessionCookie ¶ added in v0.5.46
func NewSessionCookie(r *http.Request, apiKey, tenantID string, ttl time.Duration) (*http.Cookie, error)
NewSessionCookie returns a signed HttpOnly browser session cookie.
func ParseBearerToken ¶
ParseBearerToken extracts a bearer token using case-insensitive scheme matching.
func StaticKeyMatches ¶ added in v0.5.46
StaticKeyMatches compares a candidate API key against the configured key.
func StaticKeyMiddleware ¶
StaticKeyMiddleware authenticates requests using a single static API key. Sets tenant ID to defaultTenant for all authenticated requests.