middleware

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmailSentPageData added in v0.8.0

type EmailSentPageData struct {
	PageData
	Message        string
	Detail         string
	OTPLabel       string
	OTPPlaceholder string
	VerifyButton   string
	BackLabel      string
	LoginURL       string
	VerifyOTPPath  string
}

EmailSentPageData contains data for the email sent page

type ErrorPageData added in v0.8.0

type ErrorPageData struct {
	PageData
	Message      string
	Detail       string
	ErrorDetails template.HTML // For 500 error accordion
	ActionURL    string
	ActionLabel  string
}

ErrorPageData contains data for error pages

type HealthResponse added in v0.6.0

type HealthResponse struct {
	Status     string `json:"status"`      // Current health status (starting/ready/draining/etc.)
	Live       bool   `json:"live"`        // Process is alive
	Ready      bool   `json:"ready"`       // Ready to accept traffic
	Since      string `json:"since"`       // ISO8601 timestamp of when middleware started
	Detail     string `json:"detail"`      // Human-readable detail message
	RetryAfter *int   `json:"retry_after"` // Retry after N seconds (only present when 503)
}

HealthResponse represents the JSON response for health check

type HealthStatus added in v0.6.0

type HealthStatus string

HealthStatus represents the current health status of the middleware

const (
	HealthStatusStarting   HealthStatus = "starting"
	HealthStatusWarming    HealthStatus = "warming"
	HealthStatusMigrating  HealthStatus = "migrating"
	HealthStatusPrefilling HealthStatus = "prefilling"
	HealthStatusDraining   HealthStatus = "draining"
	HealthStatusReady      HealthStatus = "ready"
)

type LoginPageData added in v0.8.0

type LoginPageData struct {
	PageData
	Providers        []ProviderData
	EmailEnabled     bool
	PasswordEnabled  bool
	EmailSendPath    string
	EmailIconPath    string
	PasswordFormHTML template.HTML
	Translations     LoginTranslations
}

LoginPageData contains data for the login page

type LoginTranslations added in v0.8.0

type LoginTranslations struct {
	Or          string
	EmailLabel  string
	EmailSave   string
	EmailSubmit string
	ThemeAuto   string
	ThemeLight  string
	ThemeDark   string
	LanguageEn  string
	LanguageJa  string
}

LoginTranslations contains translated strings for login page

type LogoutPageData added in v0.8.0

type LogoutPageData struct {
	PageData
	Message    string
	LoginURL   string
	LoginLabel string
}

LogoutPageData contains data for the logout page

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

Middleware is the core authentication middleware It implements http.Handler and can wrap any http.Handler

func New

func New(
	cfg *config.Config,
	sessionStore kvs.Store,
	oauthManager *oauth2.Manager,
	emailHandler *email.Handler,
	passwordHandler *password.Handler,
	authzChecker authz.Checker,
	forwarder forwarding.Forwarder,
	rulesEvaluator *rules.Evaluator,
	translator *i18n.Translator,
	logger logging.Logger,
) (*Middleware, error)

New creates a new authentication middleware

func (*Middleware) GetHealthStatus added in v0.6.0

func (m *Middleware) GetHealthStatus() HealthStatus

GetHealthStatus returns the current health status

func (*Middleware) IsReady added in v0.6.0

func (m *Middleware) IsReady() bool

IsReady returns true if the middleware is ready to accept traffic

func (*Middleware) ServeHTTP

func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler This is where all requests pass through

func (*Middleware) SetDraining added in v0.6.0

func (m *Middleware) SetDraining()

SetDraining marks the middleware as draining (shutting down gracefully) This should be called when receiving SIGTERM before closing connections

func (*Middleware) SetReady added in v0.6.0

func (m *Middleware) SetReady()

SetReady marks the middleware as ready to accept traffic This should be called after all initialization is complete

func (*Middleware) Wrap

func (m *Middleware) Wrap(next http.Handler) http.Handler

Wrap wraps a http.Handler with authentication This is the main entry point for using the middleware

type PageData added in v0.8.0

type PageData struct {
	Lang               i18n.Language
	Theme              i18n.Theme
	ServiceName        string
	ServiceDescription string
	Title              string
	Subtitle           string
	Header             template.HTML // Pre-rendered header HTML
	StyleLinks         template.HTML // Pre-rendered style links
	CreditIcon         string
}

PageData contains common data for all pages

type ProviderData added in v0.8.0

type ProviderData struct {
	Name     string
	IconPath string
	URL      string
	Label    string
}

ProviderData contains OAuth2 provider display data

type Templates added in v0.8.0

type Templates struct {
	// contains filtered or unexported fields
}

Templates holds all parsed templates

type ValidationError

type ValidationError struct {
	Field   string // Field name (e.g., "server.port", "session.cookie_secret")
	Message string // Error message
}

ValidationError represents a single validation error

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is a collection of validation errors

func ValidateConfig

func ValidateConfig(cfg *config.Config) ValidationErrors

ValidateConfig validates the middleware configuration Returns a list of validation errors, or nil if validation passes

func (ValidationErrors) Error

func (ve ValidationErrors) Error() string

Error implements the error interface Returns a formatted string of all validation errors

Jump to

Keyboard shortcuts

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