Skip to content

Authentication & Session Management

Authentication in a BFF application flows through several layers. Understanding how these layers connect helps you configure sessions correctly and debug problems when they arise.

After a successful login, BFF sets an HttpOnly, Secure, SameSite cookie in the browser. This cookie is the browser’s proof of session — it is sent automatically on every subsequent request to the BFF host. The cookie itself is signed and encrypted by ASP.NET Core’s data protection stack.

The browser never has access to the access token or refresh token. These are stored server-side.

By default, BFF stores session state (including tokens) inside the encrypted cookie. This works but has limitations:

Cookie-Based (default)Server-Side Sessions
Token storageInside the encrypted cookieServer-side store (DB, memory)
Cookie sizeGrows with claims/tokens — can hit browser 4KB limitFixed small size (session ID only)
Server-initiated logoutNot possible✅ Possible
Back-channel logoutNot supported✅ Supported
Session visibilityNone✅ Query all active sessions
Scale-outCookie encryption keys must be sharedSession store must be shared

Tokens stored in the session are managed automatically:

  1. Access token — When an API call is made through the BFF, the access token is retrieved from the session. If it is expired or close to expiring, BFF automatically refreshes it using the refresh token.
  2. Refresh token — Stored server-side (in the session). Revoked automatically at logout.
  3. ID token — Used during logout to send a id_token_hint to the identity provider.

See Token Management for how to access tokens programmatically.

The BFF exposes several HTTP endpoints for managing the user’s session. These endpoints are called by the frontend to trigger authentication flows or query session state.

EndpointDefault PathPurpose
Login/bff/loginStart the OIDC authentication flow
Logout/bff/logoutEnd the session and sign out
User/bff/userReturn current user claims and session state
Silent Login/bff/silent-loginNon-interactive login (deprecated in v4)
Back-Channel Logout/bff/backchannelReceive server-to-server logout notifications
Diagnostics/bff/diagnosticsShow current tokens (development only)
PageDescription
Authentication HandlersOIDC and cookie handler configuration
Server-Side SessionsPersistent session storage with Entity Framework or custom stores
OIDC PromptsControlling interactive vs. silent authentication
Login EndpointHow to trigger login from the frontend
Logout EndpointHow to trigger logout and CSRF protection
User EndpointReading user claims and session state
Back-Channel LogoutServer-initiated session termination
Silent LoginNon-interactive login (deprecated)
DiagnosticsDevelopment-time token inspection