BFF Multi-Frontend Configuration
It’s possible to configure frontends for the BFF via IConfiguration. This enables dynamic loading / changing of frontends,
including their OpenID Connect configuration and BFF Configuration.
var bffConfig = new ConfigurationBuilder() .AddJsonFile(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "BffConfig.json"), optional: false, reloadOnChange: true)
services .AddBff() .LoadConfiguration(bffConfig);The configuration supports dynamic reloading (so any new frontend added / removed is immediately reflected).
BffConfiguration
Section titled “BffConfiguration”-
defaultOidcSettingsOIDC settings applied globally to all frontends unless overridden.
Type: OidcConfiguration object (see below for properties). -
defaultCookieSettingsCookie settings applied globally to all frontends unless overridden.
Type: CookieConfiguration object (properties depend on your implementation). -
frontendsDictionary of frontend configurations.
Each key is a frontend name, and the value is a BffFrontendConfiguration object (see below).
BffFrontendConfiguration JSON Properties
Section titled “BffFrontendConfiguration JSON Properties”-
cdnIndexHtmlUrlTheindex.htmlthat should be used for this frontend (usually on a CDN). When using this property, a fallback route will be created that only proxies theindex.html. Other static assets are supposed to be retrieved directly from the CDN by the browser. Example:"https://cdn.yourapp.com/some_app/index.html" -
staticAssetsUrlThe URL where all static assets can be found. This registers a fallback route that will proxy all static assets from this URL. This is usually used during development, when you’re using a development web server such as Vite. Example:"https://localhost:3000/" -
matchingPathThe path prefix for requests routed to this frontend.
Example:"/from-config" -
matchingHostHeaderThe origin to match for this frontend.
Example:"https://localhost:5005" -
oidcOIDC settings specific to this frontend.
Type: OidcConfiguration object (see below). -
cookiesCookie settings specific to this frontend.
Type: CookieConfiguration object (see below) -
remoteApisRemote APIs for this frontend. (see below)
RemoteApiConfiguration JSON Properties
Section titled “RemoteApiConfiguration JSON Properties”-
pathMatchString. The local path that will be used to access the remote API.
Example:"/api/user-token" -
targetUriString. The target URI of the remote API.
Example:"https://localhost:5010" -
requiredTokenTypeString. The token requirement for accessing the remote API.
Possible values:"User","Client","None","OptionalUserOrClient","OptionalUserOrNone"
Default:"User" -
tokenRetrieverTypeNameString. The type name of the access token retriever to use for this remote API. -
userAccessTokenParametersObject. Parameters for retrieving a user access token (see below). -
activityTimeoutString. How long a request is allowed to remain idle between operations before being canceled.
Use C#TimeSpanserialization format, e.g."00:01:40"for 100 seconds. -
allowResponseBufferingBoolean. Allows write buffering when sending a response back to the client (if supported by the server).
Note: Enabling this can break server-sent events (SSE) scenarios.
UserAccessTokenParameters JSON Properties
Section titled “UserAccessTokenParameters JSON Properties”-
signInSchemeString. The scheme used for signing in the user (typically the cookie authentication scheme).
Example:"Cookies" -
challengeSchemeString. The authentication scheme to be used for challenges.
Example:"OpenIdConnect" -
forceRenewalBoolean. Whether to force renewal of the access token. -
resourceString. The resource for which the access token is requested.
Example:"https://api.example.com"
OidcConfiguration JSON Properties
Section titled “OidcConfiguration JSON Properties”-
clientIdThe client ID of the OpenID Connect client. -
clientSecretThe client secret of the OpenID Connect client. -
callbackPathThe path or URI to which the OpenID Connect client will redirect after authentication. -
authorityThe authority URI, typically the issuer or identity provider endpoint. -
responseTypeThe response type that the OpenID Connect client will request. -
responseModeThe response mode that the OpenID Connect client will use to return the authentication response. -
mapInboundClaimsBoolean. Whether to map inbound claims from the OpenID Connect provider to the user’s claims in the application. -
saveTokensBoolean. Whether to save the tokens received from the OpenID Connect provider. -
scopeArray of strings. The scopes that the OpenID Connect client will request from the provider. -
getClaimsFromUserInfoEndpointBoolean. Whether to retrieve claims from the UserInfo endpoint of the OpenID Connect provider.
CookieConfiguration JSON Properties
Section titled “CookieConfiguration JSON Properties”-
httpOnlyBoolean. Indicates whether the cookie is inaccessible by client-side script. Defaults to true. -
sameSiteString. The SameSite attribute of the cookie. Defaults to strictg.
Possible values:"None","Lax","Strict" -
securePolicyString. The policy used to determine if the cookie is sent only over HTTPS.
Possible values:"Always","None","SameAsRequest" -
nameString. The name of the cookie. -
maxAgeString. The max-age for the cookie. Example: “0:01:00 for 1 minute -
pathString. The cookie path. The BFF will configure the default values for this property. Example:"/" -
domainString. The domain to associate the cookie with. The BFF will configure the default values for this property.
Example:"example.com"
Example
Section titled “Example”{ "defaultOidcSettings": { "clientId": "global-client", "authority": "https://login.example.com" }, "defaultCookieSettings": null, "frontends": { "some_frontend": { "cdnIndexHtmlUrl": "https://localhost:5005/static/index.html", "matchingPath": "/from-config", "oidc": { "clientId": "frontend1-client", "scope": ["openid", "profile", "email"] } } }}