middleware

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthExemptPaths = map[string]bool{
	"/identity.IdentityService/BeginOAuthLogin":      true,
	"/identity.IdentityService/OAuthLogin":           true,
	"/identity.IdentityService/PasswordLogin":        true,
	"/identity.IdentityService/PasswordSignup":       true,
	"/identity.IdentityService/RefreshToken":         true,
	"/identity.IdentityService/Logout":               true,
	"/identity.IdentityService/GetCurrentUser":       true,
	"/identity.IdentityService/BeginPasskeyLogin":    true,
	"/identity.IdentityService/CompletePasskeyLogin": true,
	"/identity.IdentityService/InitiateQrLogin":      true,
	"/identity.IdentityService/PollQrLogin":          true,
	"/identity.IdentityService/AcceptInvitation":     true,
	"/identity.IdentityService/RequestAdminHelp":     true,
	"/identity.IdentityService/VerifyTotp":           true,

	"/identity.IdentityService/RequestPasswordReset": true,
	"/identity.IdentityService/ConfirmPasswordReset": true,
	"/identity.IdentityService/VerifyEmail":          true,

	"/identity.IdentityService/ConfirmEmailChange": true,
	"/.well-known/jwks.json":                       true,
	"/health":                                      true,
	"/healthz":                                     true,
}

AuthExemptPaths lists URL paths that do not require a valid JWT. Connect-Go uses the proto service/method as the URL path.

Functions

func AuthMiddleware

func AuthMiddleware(keyRing *jwtpkg.KeyRing, expectedTenant string) func(http.Handler) http.Handler

AuthMiddleware verifies JWT Bearer tokens on non-exempt paths and injects the authenticated user ID into the X-Authenticated-User-Id request header so downstream Connect handlers can read it.

expectedTenant, when non-empty, is enforced on every verified token: tokens whose "tenant" claim does not match are rejected. Pass an empty string to disable the cross-tenant check.

For auth-exempt paths the middleware still attempts to parse and verify a token when one is present (e.g. GetCurrentUser may optionally read the caller identity) but never rejects the request.

func CORSMiddleware

func CORSMiddleware(allowedOrigins string) func(http.Handler) http.Handler

CORSMiddleware handles CORS preflight requests and injects the appropriate response headers for allowed origins.

allowedOrigins is a comma-separated list of origins (e.g. "http://localhost:9002,http://localhost:3000").

func HealthMiddleware

func HealthMiddleware(next http.Handler) http.Handler

HealthMiddleware handles /health, /healthz, and / before the request reaches the Connect handler. This keeps health probes (e.g. Azure Container Apps) cheap and independent of service readiness.

func JWKSMiddleware

func JWKSMiddleware(keyRing *jwtpkg.KeyRing) func(http.Handler) http.Handler

JWKSMiddleware serves the /.well-known/jwks.json endpoint from the key ring. The response contains the RSA public keys for all keys in the ring so that third-party services can verify tokens without sharing a secret.

func LoggingMiddleware

func LoggingMiddleware(logger *zap.Logger) func(http.Handler) http.Handler

LoggingMiddleware logs every request's method, path, response status code, duration, and remote address using the provided zap logger.

Types

This section is empty.

Jump to

Keyboard shortcuts

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