-
Release v0.9.0 Stable
released this
2026-03-19 07:46:31 -06:00 | 0 commits to main since this releasev0.9.0
code.nochebuena.dev/go/httpauth-firebaseOverview
httpauth-firebaseprovides three composablenet/httpmiddleware functions that
implement the full Firebase authentication and authorization stack for HTTP services.
The output contract is alwaysrbac.Identity— downstream handlers and business
logic are completely decoupled from Firebase types.This release reflects an API designed through multiple architecture reviews and
validated end-to-end via the todo-api POC. It is versioned at v0.9.0 rather than
v1.0.0 because it has not yet been exercised in production workloads across all edge
cases, preserving the option for minor API refinements before committing to full
stability.What's Included
AuthMiddleware(verifier TokenVerifier, publicPaths []string) func(http.Handler) http.HandlerVerifies the
Authorization: Bearer <token>header via Firebase JWT verification
and injects the uid and raw claims into the request context. Requests matching any
pattern inpublicPathsare passed through without token verification. Returns 401
on missing or invalid tokens.EnrichmentMiddleware(enricher IdentityEnricher, opts ...EnrichOpt) func(http.Handler) http.HandlerReads the uid and claims injected by
AuthMiddleware, calls the application-provided
IdentityEnricher, and stores the resultingrbac.Identityin context via
rbac.SetInContext. Supports an optional tenant header viaWithTenantHeader. Returns
401 ifAuthMiddlewaredid not run upstream; returns 500 if the enricher fails.AuthzMiddleware(provider PermissionProvider, resource string, required rbac.Permission) func(http.Handler) http.HandlerReads
rbac.Identityfrom context (set byEnrichmentMiddleware), resolves the
permission mask via the application-providedPermissionProvider, and gates the
request against the required permission bit. Returns 401 if no identity is in context;
returns 403 if the permission check fails or the provider errors.Interfaces
TokenVerifier— abstracts*auth.Clientfor unit-test mockability; production code passes the Firebase auth client directlyIdentityEnricher— application-implemented; receives uid and raw claims, returnsrbac.IdentityPermissionProvider— application-implemented; receives uid and resource name, returnsrbac.PermissionMask
Options
WithTenantHeader(header string) EnrichOpt— reads a tenant ID from a named request header and attaches it to the identity
Installation
go get code.nochebuena.dev/go/httpauth-firebase@v0.9.0Requires
code.nochebuena.dev/go/rbacandfirebase.google.com/go/v4.Design Highlights
Provider-specific naming. The module is named
httpauth-firebasebecause it
imports the Firebase SDK directly. Other auth providers (Auth0, JWKS, etc.) live in
sibling modules that all converge on the samerbac.Identityoutput contract. This
leaves the door open forhttpauth-auth0orhttpauth-jwtwithout naming conflicts.Three composable middleware, not one monolith.
AuthMiddleware,EnrichmentMiddleware,
andAuthzMiddlewareare separate functions. Each can be applied independently at the
router level or on individual route groups. A webhook endpoint might use only
AuthMiddleware; a protected CRUD resource uses all three.rbac.Identityas the only output contract. OnceEnrichmentMiddlewareruns,
downstream code reads identity exclusively viarbac.FromContext. No Firebase type
leaks past the middleware boundary.No logger dependency. Errors are returned as HTTP responses. The module does not
accept a logger parameter, keeping its dependency surface minimal.Glob-based public path bypass. Public paths use
path.Matchpatterns (*wildcard
supported), applied per request before any token parsing occurs.Known Limitations & Edge Cases
publicPathsmatching usespath.Match(glob only). Regular expressions and
prefix matching are not supported. A path like/api/v1/public/*requires an
explicit*at the end;/api/v1/publicdoes not match/api/v1/public/foo.- No refresh token handling. Revoked tokens are detected via
VerifyIDTokenAndCheckRevoked, but the middleware does not issue or refresh tokens. - No claims caching.
IdentityEnricher.Enrichis called on every request. Applications
with expensive enrichment (e.g., database lookups) should implement their own caching
inside the enricher. EnrichmentMiddlewarereturns a generic 500 if the enricher fails; the specific error
is not surfaced to the client. Log the error inside your enricher implementation.AuthzMiddlewaretreats both provider errors and permission-check failures as 403.
The two cases are intentionally indistinguishable to callers.
v0.9.0 → v1.0.0 Roadmap
- Evaluate whether
publicPathsshould support prefix matching in addition to glob patterns - Add an optional error hook or logger interface so enricher/provider errors can be observed without coupling to a specific logger
- Consider claims caching support (e.g., an optional
IdentityCacheinterface) for high-throughput services - Validate behavior under token revocation race conditions
- Production hardening across multiple deployed services
Downloads