Storefront has been decoupled into micro-frontends with a dedicated commerce app and shared shell.

Read the architecture guide →

Authentication & Session Boundaries

Identity provider handoff, origin-scoped session cookies, edge route protection, and role-based UI gating across customer and staff surfaces.

ArchitectureReference

Purpose & Scope

This reference defines the authentication, session management, and authorization boundaries across Storefront, Commerce, and Backoffice. It governs how user identities are established with Microsoft Entra ID, how origin-scoped session cookies flow behind the API Gateway, and how frontend route protection pairs with backend API enforcement.

Authentication and Session Boundary

The visual below traces how an unauthenticated user transitions through the API Gateway, completes OAuth2/OIDC handoff with Microsoft Entra ID, establishes an origin-scoped session cookie, and accesses protected APIs with a Bearer token.

Loading graph...

Architectural Principles & Rules

  • External identity delegation: BookWorm does not store passwords or issue standalone user credentials; all customer and staff authentication delegates to Microsoft Entra ID via OAuth2/OIDC.
  • Two distinct session owners: Storefront owns the customer authentication callback and session lifecycle (shared transparently with Commerce over the single gateway origin). Backoffice owns a separate staff session handler with administrative OAuth2 scopes.
  • Edge & layout route protection: Commerce enforces session-cookie presence at the edge proxy before rendering protected basket, checkout, or account routes, redirecting unauthenticated users to Storefront sign-in with a preserved return URL. Backoffice enforces an administrative authentication guard at the layout boundary.
  • Defense-in-depth authorization: UI gating and route guards improve user experience only; every backend capability API independently validates JWT Bearer tokens, audiences, and Entra ID roles/scopes on every request.
Never Rely Solely on Client UI Gating

Hiding a button or protecting a frontend route is never a security boundary. Backend APIs must enforce role and scope authorization on every operation regardless of frontend state.

Patterns & Boundaries

Concern / SurfaceArchitectural ApproachResponsibility BoundaryKey Trade-off
Customer Session (Storefront + Commerce)Single origin-scoped session cookie owned by Storefront and read by CommerceStorefront owns OAuth2 callback; Commerce validates session cookie on protected routesCommerce depends on Storefront availability for initial login handoffs
Staff Session (Backoffice)Dedicated staff session handler mounted under the Backoffice base pathBackoffice owns staff sign-in and requests elevated catalog/ordering/review scopesSeparate session lifecycle isolates staff credentials from customer browsing
API Token PropagationCentralized token provider injects Bearer tokens into gateway-bound API requestsAuth layer supplies current access token; transport layer attaches authorization headersRequires clean token refresh and immediate redirect on 401 Unauthorized
AI Assistant IdentityServer-side assistant runtime forwards authenticated customer context to Chat APIStorefront server runtime bridges session to AG-UI; Chat API handles downstream OBO exchangeKeeps Entra Agent Identity OBO credentials strictly on the backend

Quality & Operational Impact

  • Seamless Customer Journey: Origin-scoped session cookies allow shoppers to sign in on Storefront and immediately check out in Commerce without re-authenticating.
  • Reduced Attack Surface: Keeping OAuth2 callbacks and token exchanges server-side behind the API Gateway prevents exposing client secrets or OBO credentials to browser code.
  • Zero Silent Auth Failures: Failing 401 responses halt retries immediately and guide users cleanly through re-authentication.