middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchPublicKeys

func FetchPublicKeys(issuerURL string) (map[string]*rsa.PublicKey, error)

FetchPublicKeys fetches JWKS from the issuer's OIDC discovery endpoint

func GetUserIDFromContext

func GetUserIDFromContext(r *http.Request) string

GetUserIDFromContext retrieves the user ID from the request context

func JWTAuth

func JWTAuth(validator *JWTValidator) func(http.Handler) http.Handler

JWTAuth is a middleware that validates JWT tokens from Authentik

func Logging

func Logging(l *slog.Logger, next http.Handler) http.Handler

Logging wraps an http.Handler for access logging.

func NotifierValidator

func NotifierValidator(next http.Handler) http.Handler

NotifierValidator validates the Shoutrrr URL in the notifier field for POST requests

func Prometheus

func Prometheus(next http.Handler) http.Handler

Prometheus wraps an http.Handler to provide prometheus metrics for the route.

func SecurityHeaders

func SecurityHeaders(next http.Handler) http.Handler

SecurityHeaders adds standard security headers to every response.

func SwitchValidator

func SwitchValidator(v *validator.Validate) func(http.Handler) http.Handler

SwitchValidator handles JSON decoding and struct validation

Types

type JWTValidator

type JWTValidator struct {
	Audience   string
	Enabled    bool
	IssuerURL  string
	PublicKeys map[string]*rsa.PublicKey
}

JWTValidator holds configuration for JWT validation

type ValidatedSwitch

type ValidatedSwitch struct {
	Payload                   api.Switch
	CheckInIntervalDuration   time.Duration
	ReminderThresholdDuration *time.Duration // Pointer since reminder is optional
}

ValidatedSwitch contains parsed payload/time fields to prevent parsing twice.

func FromContext

func FromContext(ctx context.Context) (ValidatedSwitch, bool)

FromContext grabs a Switch payload from the context to ensure we only read the body once since we read the body to perform validation in this middleware.

Jump to

Keyboard shortcuts

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