Authentication architecture
Building an Auth0 BFF architecture for Product
The problem
The platform needed one secure authentication boundary across a React frontend, backend APIs, agent services, integrations, organization access, RBAC, and audit requirements.
The solution
Introduced a Backend for Frontend that centralizes Auth0 integration and application sessions while leaving authorization and business rules inside the backend services.
The result
Authentication became a clear trust boundary: Auth0 establishes identity, the BFF manages the session, and backend services enforce organization-aware permissions.
System architecture
- Request reaches the edge
- Ingress forwards to the BFF
- BFF hands login to Auth0
- Auth0 returns the identity
- Session stored in Redis
- ia_session issued
- Trusted identity to the API
- Casbin checks the permission
- Allowed
- Operation runs on PostgreSQL
Architecture decision 1 of 9
The problem
The platform brought together a React frontend, multiple backend APIs, agent services, ITSM and infrastructure integrations, a service mesh, organization-based access, backend RBAC, and audit requirements.
A direct browser-to-service design would force every backend service to understand Auth0, JWT validation, token claims, organization context, session behavior, and authentication failures. As services grow, that logic becomes duplicated and harder to secure consistently.
Architecture decision 2 of 9
Why a BFF
A Backend for Frontend sits between the browser and internal APIs. Instead of sending the browser directly to every service, the browser uses one controlled entry point for authentication.
The BFF establishes who the user is; it does not replace authorization inside the backend. Backend services still decide what that user is allowed to do.
Architecture decision 3 of 9
The complete architecture
The architecture is organized into client, edge, authentication, platform, and persistence layers. The key boundary is between the public browser and the trusted identity context passed to internal APIs.
The BFF is the authentication boundary, while backend services remain the authorization boundary.
Architecture decision 4 of 9
Authentication and application sessions
Auth0 owns identity concerns such as login, MFA, account recovery, identity verification, and OAuth/OIDC. After successful authentication, the BFF creates an application session so the browser does not repeat the full Auth0 flow on every API request.
The session is represented by an ia_session cookie. Auth0 answers who the user is; the application session gives the platform a stable way to recognize that identity during subsequent requests.
- Request a protected page
- Redirect to Auth0
- Log in at Auth0
- Authorization response
- Callback to the BFF
- Validate and exchange
- Authenticated identity
- Create application session
- Set ia_session cookie
Architecture decision 5 of 9
Organization-aware authorization
The BFF establishes the authenticated identity and organization context. Backend services then use that context when evaluating permissions with Casbin-based RBAC.
A valid Auth0 login does not grant access to every operation. The backend checks organization, role, and permission before allowing an API operation, which protects tenant boundaries.
Architecture decision 6 of 9
The request path after login
Once a session exists, the browser sends the ia_session cookie with a request. The BFF validates the application session and forwards trusted identity context to the API, where authorization is evaluated before data or infrastructure operations run.
Architecture decision 7 of 9
Clear service responsibilities
The BFF owns authentication, session management, Auth0 integration, identity extraction, organization context, authentication-related auditing, and session security.
Backend services own business logic, authorization, RBAC, infrastructure operations, agent execution, ITSM operations, data access, and approval gates. This keeps the BFF from becoming a second business-logic service.
Architecture decision 8 of 9
Sessions, persistence, and failure handling
Redis is suited to fast, ephemeral application session state. PostgreSQL/CNPG remains the durable store for application and compliance data. Keeping those roles distinct prevents convenient cache state from becoming the authoritative security record.
Authentication failures stop at the authentication boundary: no session or an invalid session returns 401 Unauthorized. An authenticated user who fails an RBAC check receives 403 Forbidden.
Architecture decision 9 of 9
Why this architecture works
The central decision is separating identity from authorization. Auth0 provides the identity foundation, the BFF manages the browser authentication boundary and session, and backend services own authorization and business rules.
That separation also leaves room for other authentication paths, such as PATs, CLI access, automation, and machine-to-machine integrations, without weakening the browser security boundary.
More case studies
Machine authentication
Designing a secure PAT architecture for Product
The problem
CLI clients, automation, and external integrations cannot use a browser session, but still need durable API credentials that are revocable, scoped, auditable, and isolated to an organization.
AI systems
Making AI workflows predictable
The problem
Model output could be useful but inconsistent, making it hard to trust automated actions in a production workflow.
Frontend architecture
Keeping complex interfaces responsive
The problem
Large dashboards accumulated expensive renders and tightly coupled UI states as more data and workflows were added.