middleware

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAllowedAPIOrigins = "*"
	DefaultAllowedMethods    = "GET,POST,PUT,PATCH,DELETE,OPTIONS"
	DefaultAllowedHeaders    = "Content-Type,Authorization"
)

Variables

This section is empty.

Functions

func EnableCORS

func EnableCORS(cfg *CORSConfig, next http.Handler) http.Handler

func ExtractAndSetTokenMiddleware

func ExtractAndSetTokenMiddleware(next http.Handler) http.Handler

ExtractAndSetTokenMiddleware extracts token from Authorization header or auth_token cookie and injects it into the context under libauth.ContextTokenKey.

func JWTAuthMiddleware

func JWTAuthMiddleware(tokenManager AuthzManager, next http.Handler) http.Handler

JWTAuthMiddleware validates the token and enriches context with identity & permissions.

func JWTRefreshMiddleware

func JWTRefreshMiddleware(tokenManager AuthzManager, next http.Handler) http.Handler

JWTRefreshMiddleware attempts to refresh the token for browser clients. Should be placed AFTER ExtractAndSetTokenMiddleware but BEFORE JWTAuthMiddleware

func RequireAuth

func RequireAuth(next http.Handler) http.Handler

TODO: when do we consider that auth can be passed?

Types

type AuthZReader

type AuthZReader interface {
	GetIdentity(ctx context.Context) (string, error)
	GetUsername(ctx context.Context) (string, error)
	GetPermissions(ctx context.Context) (libauth.Authz, error)
	GetTokenString(ctx context.Context) (string, error)
	GetExpiresAt(ctx context.Context) (time.Time, error)
}

type AuthzManager

type AuthzManager interface {
	RefreshToken(ctx context.Context, tokenString string, withGracePeriod *time.Duration) (string, bool, time.Time, error)
	CreateAuthToken(ctx context.Context, subject string, permissions libauth.Authz) (string, time.Time, error)
	ValidateAuthToken(ctx context.Context) (context.Context, error)
	SetToken(ctx context.Context, tokenString string) (context.Context, error)
	AuthZReader
}

type CORSConfig

type CORSConfig struct {
	AllowedAPIOrigins string `json:"allowed_api_origins"`
	AllowedMethods    string `json:"allowed_methods"`
	AllowedHeaders    string `json:"allowed_headers"`
	ProxyOrigin       string `json:"proxy_origin"`
}

type LoginManager

type LoginManager interface {
	Login(ctx context.Context, username, password string) (LoginResponse, error)
}

type LoginResponse

type LoginResponse struct {
	Token     string    `json:"token"`
	ExpiresAt time.Time `json:"expires_at"`
	UserID    string    `json:"user_id"`
	Username  string    `json:"username"`
}

func GetLoginResponse

func GetLoginResponse(ctx context.Context, auth AuthZReader) (LoginResponse, error)

Jump to

Keyboard shortcuts

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