auth

package
v0.5.58 Latest Latest
Warning

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

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

Documentation

Overview

Package auth provides authentication middleware and context helpers.

Index

Constants

View Source
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

func AuthenticateStaticRequest(r *http.Request, apiKey, defaultTenant string) (string, bool)

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

func ClearSessionCookie(r *http.Request) *http.Cookie

ClearSessionCookie returns a Set-Cookie value that expires the browser session.

func ExtractTenantHeader

func ExtractTenantHeader(header string) string

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

func ParseBearerToken(header string) string

ParseBearerToken extracts a bearer token using case-insensitive scheme matching.

func StaticKeyMatches added in v0.5.46

func StaticKeyMatches(apiKey, candidate string) bool

StaticKeyMatches compares a candidate API key against the configured key.

func StaticKeyMiddleware

func StaticKeyMiddleware(apiKey, defaultTenant string) func(http.Handler) http.Handler

StaticKeyMiddleware authenticates requests using a single static API key. Sets tenant ID to defaultTenant for all authenticated requests.

func TenantID

func TenantID(ctx context.Context) string

TenantID retrieves the tenant ID from the context. Returns empty string if not set.

func WithTenantID

func WithTenantID(ctx context.Context, tenantID string) context.Context

WithTenantID stores a tenant ID in the context.

Types

type KeyStoreAuthFunc

type KeyStoreAuthFunc func(ctx context.Context, plaintext string) (tenantID string, err error)

KeyStoreAuthFunc is a function that looks up a key and returns a tenant ID.

Jump to

Keyboard shortcuts

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