Configuration Options
The Duende.BFF.BffOptions allows to configure several aspects of the BFF framework.
You set the options at startup time:
builder.Services.AddBff(options =>{ // configure options here...})General
Section titled “General”-
EnforceBffMiddlewareEnables checks in the user management endpoints that ensure that the BFF middleware has been added to the pipeline. Since the middleware performs important security checks, this protects from accidental configuration errors. You can disable this check if it interferes with some custom logic you might have. Defaults to true.
-
LicenseKeyThis sets the license key for Duende.BFF. A license key is required for production deployments. See licensing for details about how to configure the license key.
-
AnonymousSessionResponse(added in 2.0)This sets the response status code behavior on the user endpoint to either return 401 or 200 with a null payload when the user is anonymous.
-
DiagnosticsEnvironmentsThe ASP.NET environment names that enable the diagnostics endpoint. Defaults to “Development”.
-
BackChannelHttpHandlerA HTTP message handler that’s used to configure backchannel communication. Typically used during testing. Configuring this will automatically configure the BackChannelHttpHandler property in OpenIDConnectOptions and also set it as the primary http message handler for retrieving the index.html.
-
AutomaticallyRegisterBffMiddleware(added in 4.0)When using BFF V4 with multiple frontends, several middlewares are automatically added to the pipeline (frontend selection, path mapping, OpenID Connect callbacks, management endpoints, and static file proxying). If you need full control over the middleware pipeline, set this to
falseand register the middleware manually:builder.Services.AddBff(options =>{options.AutomaticallyRegisterBffMiddleware = false;});When disabled, you must call
UseBffPreProcessing()early in the pipeline (before authentication) andUseBffPostProcessing()at the end:app.UseForwardedHeaders();app.UseBffPreProcessing(); // Frontend selection, path mapping, OpenID callbacksapp.UseAuthentication();app.UseRouting();app.UseBff(); // Anti-forgery checksapp.UseAuthorization();// map your endpoints here...app.UseBffPostProcessing(); // Management endpoints, remote API handling, static file proxyingYou can also use the individual middleware methods for even more granular control:
UseBffFrontendSelection()— Selects the current frontend based on host/path matchingUseBffPathMapping()— AdjustsPathBaseandPathfor the selected frontendUseBffOpenIdCallbacks()— Handles OpenID Connect callback requestsUseBffAntiForgery()— Validates anti-forgery headers (same asUseBff())UseBffStaticFileProxying()— Proxies static file requests to CDN or development server
-
StaticAssetsClientNameIf BFF is configured to automatically retrieve the
index.html, or to proxy the static assets, it needs an HTTP client to do so. With this name, you can automatically configure this HTTP client in theHttpClientFactory. -
AllowedSilentLoginReferersFor silent login to work, you normally need to have the BFF backend and the frontend on the same origin. If you have a split host scenario, meaning the backend on a different origin (but same site) as the frontend, then you can use the referer header to differentiate which browser window to post the silent login results to. This array must then contain the list of allowed referer header values.
-
LoginPathSets the path to the login endpoint. Defaults to /bff/login.
-
SilentLoginPathSets the path to the silent login endpoint. Defaults to /bff/silent-login.
-
SilentLoginCallbackPathSets the path to the silent login callback endpoint. Defaults to /bff/silent-login-callback.
-
LogoutPathSets the path to the logout endpoint. Defaults to /bff/logout.
-
UserPathSets the path to the user endpoint. Defaults to /bff/user.
-
BackChannelLogoutPathSets the path to the backchannel logout endpoint. Defaults to /bff/backchannel.
-
DiagnosticsPathSets the path to the diagnostics endpoint. Defaults to /bff/diagnostics.
Session Management
Section titled “Session Management”-
ManagementBasePathBase path for management endpoints. Defaults to /bff.
-
RequireLogoutSessionIdFlag that specifies if the
sidclaim needs to be present in the logout request as query string parameter. Used to prevent cross site request forgery. Defaults totrue. -
RevokeRefreshTokenOnLogoutSpecifies if the user’s refresh token is automatically revoked at logout time. Defaults to
true. -
BackchannelLogoutAllUserSessionsSpecifies if during backchannel logout all matching user sessions are logged out. If
true, all sessions for the subject will be revoked. If false, just the specific session will be revoked. Defaults tofalse. -
~~EnableSessionCleanup~~(removed in V4)Indicates if expired server side sessions should be cleaned up. This requires an implementation of IUserSessionStoreCleanup to be registered in the ASP.NET Core service provider. Defaults to
false.In V4, you need to opt into this value by calling
.AddSessionCleanupBackgroundProcess() -
SessionCleanupIntervalInterval at which expired sessions are cleaned up. Defaults to 10 minutes.
-
AntiForgeryHeaderNameSpecifies the name of the header used for anti-forgery header protection. Defaults to
X-CSRF. -
AntiForgeryHeaderValueSpecifies the expected value of Anti-forgery header. Defaults to
1. -
DPoPJsonWebKeySpecifies the Json Web Key to use when creating DPoP proof tokens. Defaults to null, which is appropriate when not using DPoP.
-
RemoveSessionAfterRefreshTokenExpirationFlag that specifies if a user session should be removed after an attempt to use a Refresh Token to acquire a new Access Token fails. This behavior is only triggered when proxying requests to remote APIs with TokenType.User or TokenType.UserOrClient. Defaults to True. -
DisableAntiForgeryCheck(added in V4) A delegate that determines if the anti-forgery check should be disabled for a given request. The default is not to disable anti-forgery checks.
CDN / Static Assets
Section titled “CDN / Static Assets”-
IndexHtmlDefaultCacheDuration(added in V4)If you use CDN Index HTML proxying (via
BffFrontend.CdnIndexHtmlUrl), this controls how long the fetchedindex.htmlis cached. Defaults to 5 minutes.
Diagnostics
Section titled “Diagnostics”-
Diagnostics(added in V4)Options that control the way that diagnostic data is logged. This is a nested options object with the following properties:
LogFrequency— Frequency at which diagnostic summaries are logged. Defaults to 1 hour.ChunkSize— Max size of diagnostic data log message chunks in bytes. Defaults to 8160 bytes (8 KB minus 32 bytes for log message formatting overhead).
BFF Blazor Server Options
Section titled “BFF Blazor Server Options”In the Blazor Server, you configure the BffBlazorServerOptions by using the AddBlazorServer method.
builder.Services.AddBlazorServer(opt =>{ // configure options here..})The following options are available:
-
ServerStateProviderPollingIntervalThe delay, in milliseconds, between polling requests by the BffServerAuthenticationStateProvider to the /bff/user endpoint. Defaults to 5000 ms.
BFF Blazor Client Options
Section titled “BFF Blazor Client Options”In WASM, you configure the BffBlazorClientOptions using the AddBffBlazorClient method:
builder.Services.AddBffBlazorClient(opt =>{ // configure options here...})The following options are available:
-
RemoteApiPathThe base path to use for remote APIs.
-
RemoteApiBaseAddressThe base address to use for remote APIs. If unset (the default), the blazor hosting environment’s base address is used.
-
StateProviderBaseAddressThe base address to use for the state provider’s calls to the /bff/user endpoint. If unset (the default), the blazor hosting environment’s base address is used.
-
WebAssemblyStateProviderPollingDelayThe delay, in milliseconds, before the BffClientAuthenticationStateProvider will start polling the /bff/user endpoint. Defaults to 1000 ms.
-
WebAssemblyStateProviderPollingIntervalThe delay, in milliseconds, between polling requests by the BffClientAuthenticationStateProvider to the /bff/user endpoint. Defaults to 5000 ms.
Proxy Servers and Load Balancers v4.0
Section titled “Proxy Servers and Load Balancers ”v4.0When your BFF is hosted behind another reverse proxy or load balancer, you’ll want to use X-Forwarded-* headers.
BFF automatically registers the ForwardedHeaders middleware in the pipeline, without any additional configuration. You will need to configure which headers should be considered by the middleware, typically the X-Forwarded-For and X-Forwarded-Proto headers. Here’s an example of how you can configure this.
builder.Services.Configure<ForwardedHeadersOptions>(options =>{ // Consider configuring the 'KnownProxies' and the 'AllowedHosts' to prevent IP spoofing attacks options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;});See proxy servers and load balancers in the Microsoft documentation for more information.