liveBook · Manning

Backend-for-frontend pattern

As explained in ASP.NET Core in Action, 3e

Backend for Frontend is an architecture pattern that provides a dedicated backend for a particular frontend, handling authentication and translating or forwarding frontend requests to downstream APIs.

The Backend for Frontend (BFF) pattern places a traditional ASP.NET Core application between a SPA and its real APIs. It authenticates users, stores bearer tokens securely, issues an authentication cookie, and forwards authenticated requests. section 25.2

A typical request flow is:

  • The user authenticates through OpenID Connect at the ASP.NET Core backend. section 25.2
  • The backend stores the bearer tokens and gives the browser an authentication cookie instead. section 25.2
  • The SPA sends requests with the cookie; the backend exchanges it for the appropriate bearer token and forwards each request to the real API. section 25.2

SPA without browser-held bearer tokens

A Blazor WebAssembly, React, or Angular frontend calls its ASP.NET Core backend using the authentication cookie. The backend adds the bearer token when calling the protected API, so the browser never receives that token. section 25.2

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains the authentication and forwarding flow, but does not detail implementation configuration or backend endpoint code.
Examples
Uses Blazor WebAssembly, React, and Angular frontends calling an ASP.NET Core backend that forwards requests to a real API.
What you can do after
Operate a SPA without exposing its API bearer tokens to the browser, while accepting the cost of an additional backend service.
How it connects
Connects authentication cookies with bearer token authentication, OpenID Connect, SPAs, and downstream APIs.

Also explained in

Compare how 4 books explain backend-for-frontend pattern →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.