middleware

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCSRFCookieMissing = errors.New("csrf cookie token missing")
	ErrCSRFTokenMissing  = errors.New("csrf token missing in request")
	ErrCSRFTokenInvalid  = errors.New("csrf token invalid")
)

Functions

func HTMXMiddleware added in v0.1.12

func HTMXMiddleware(next http.Handler) http.Handler

func LimitRequestBody added in v0.20.0

func LimitRequestBody(maxBytes int64) func(http.Handler) http.Handler

func OptionalAccessIdentity added in v0.1.16

func OptionalAccessIdentity(
	sessionSvc *session.Service,
	audience token.Audience,
	now func() time.Time,
) func(http.Handler) http.Handler

func RedirectIfAuthenticated

func RedirectIfAuthenticated(sessionService *session.Service, now func() time.Time) func(http.Handler) http.Handler

func RequestLogger

func RequestLogger(logger *slog.Logger) func(http.Handler) http.Handler

func RequireAPIAccessAuth

func RequireAPIAccessAuth(sessionSvc *session.Service, audience token.Audience, now func() time.Time) func(http.Handler) http.Handler

func RequireAPICSRF

func RequireAPICSRF(next http.Handler) http.Handler

func RequireAccessAuthWithRefresh

func RequireAccessAuthWithRefresh(
	sessionSvc *session.Service,
	audience token.Audience,
	accessTTL time.Duration,
	refreshTTL time.Duration,
	now func() time.Time,
) func(http.Handler) http.Handler

RequirePageAccessAuthWithRefresh protects Authara-rendered pages + HTMX actions. It validates the access token, and if it's missing/expired it will try to refresh using the refresh token cookie. If refresh fails, it redirects to login.

func RequireAccessAuthWithRefreshPolicy added in v0.21.0

func RequireAccessAuthWithRefreshPolicy(
	sessionSvc *session.Service,
	audience token.Audience,
	policy config.SessionCookiePolicyReader,
	now func() time.Time,
) func(http.Handler) http.Handler

func RequireAdmin

func RequireAdmin(next http.Handler) http.Handler

func RequireAllowlistEnabled added in v0.1.23

func RequireAllowlistEnabled(enabled bool) func(http.Handler) http.Handler

func RequireAllowlistEnabledWithPolicy added in v0.21.0

func RequireAllowlistEnabledWithPolicy(policy config.AllowlistPolicyReader) func(http.Handler) http.Handler

func RequireCSRF

func RequireCSRF(next http.Handler) http.Handler

func RequireChallengeEnabled added in v0.1.14

func RequireChallengeEnabled(enabled bool) func(http.Handler) http.Handler

func RequireInternalAPIAuth added in v0.1.24

func RequireInternalAPIAuth(token string) func(http.Handler) http.Handler

func RequireOperator added in v0.20.0

func RequireOperator(next http.Handler) http.Handler

RequireOperator allows only identities with the exact operator platform role. Other privileged roles do not imply operator access.

func RequirePublicOrganizationManagement added in v0.1.27

func RequirePublicOrganizationManagement(enabled bool) func(http.Handler) http.Handler

func RequirePublicOrganizationManagementWithPolicy added in v0.21.0

func RequirePublicOrganizationManagementWithPolicy(policy config.OrganizationPolicyReader) func(http.Handler) http.Handler

func ReturnTo

func ReturnTo(next http.Handler) http.Handler

func ReturnToWithDefault added in v0.10.0

func ReturnToWithDefault(defaultReturnTo string) func(http.Handler) http.Handler

func ReturnToWithPolicy added in v0.21.0

func ReturnToWithPolicy(policy config.UIPolicyReader) func(http.Handler) http.Handler

func SecurityHeaders added in v0.1.23

func SecurityHeaders(cfg SecurityHeadersConfig) func(http.Handler) http.Handler

Types

type SecurityHeadersConfig added in v0.1.23

type SecurityHeadersConfig struct {
	AllowGoogleOAuth bool
}

Jump to

Keyboard shortcuts

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