Skip to content

Commit 9bfaf44

Browse files
authored
Merge pull request #966 from DuendeSoftware/wca/bff-host-not-origin
Replacing origin with host in multi-frontend docs
2 parents 1e72d53 + 8090761 commit 9bfaf44

File tree

5 files changed

+54
-22
lines changed

5 files changed

+54
-22
lines changed

src/content/docs/bff/architecture/multi-frontend.md

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,59 @@ sidebar:
1010
variant: tip
1111
---
1212

13-
BFF V4.0 introduces the capability to support multiple BFF Frontends in a single host. This helps to simplify your application landscape by consolidating multiple physical BFF Hosts into a single deployable unit.
13+
BFF V4.0 introduces the capability to support multiple BFF Frontends in a single host. This helps to simplify your
14+
application landscape by consolidating multiple physical BFF Hosts into a single deployable unit.
1415

1516
A single BFF setup consists of:
1617
1. A browser based application, typically built using technology like React, Angular or VueJS. This is typically deployed to a Content Delivery Network (CDN).
1718
2. A BFF host, that will take care of the OpenID Connect login flows.
1819
3. An API surface, exposed and protected by the BFF.
1920

20-
With the BFF Multi-frontend support, you can logically host multiple of these BFF Setups in a single host. The concept of a single frontend (with OpenID Connect configuration, an API surface and a browser based app) is now codified inside the BFF. By using a flexible frontend selection mechanism (using Origins or Paths to distinguish), it's possible to create very flexible setups.
21+
With the BFF Multi-frontend support, you can logically host multiple of these BFF Setups in a single host. The concept
22+
of a single frontend (with OpenID Connect configuration, an API surface and a browser based app) is now codified inside
23+
the BFF. By using a flexible frontend selection mechanism (using Hosts or Paths to distinguish), it's possible to
24+
create very flexible setups.
2125

22-
The BFF dynamically configures the aspnet core authentication pipeline according to recommended practices. For example, when doing Origin based routing, it will configure the cookies using the most secure settings and with the prefix [`__Host`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie).
26+
The BFF dynamically configures the aspnet core authentication pipeline according to recommended practices. For example,
27+
when doing Host based routing, it will configure the cookies using the most secure settings and with the prefix
28+
[`__Host`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie).
2329

24-
Frontends can be added or removed dynamically from the system, without having to restart the system. You can do this via configuration (for example by modifying a configuration file) or programmatically.
30+
Frontends can be added or removed dynamically from the system, without having to restart the system. You can do this
31+
via configuration (for example by modifying a configuration file) or programmatically.
2532

2633
:::note
27-
The Duende BFF V4 library doesn't ship with an abstraction to store or read frontends from a database. It's possible to implement this by creating your own store (based on your requirements), then modify the `FrontendCollection` at run-time.
34+
The Duende BFF V4 library doesn't ship with an abstraction to store or read frontends from a database. It's possible
35+
to implement this by creating your own store (based on your requirements), then modify the `FrontendCollection` at
36+
run-time.
2837
:::
2938

3039
## A Typical Example
3140

32-
Consider an enterprise that hosts multiple browser based applications. Each of these applications is developed by a separate team and as such, has its own deployment schedule.
41+
Consider an enterprise that hosts multiple browser based applications. Each of these applications is developed by a
42+
separate team and as such, has its own deployment schedule.
3343

34-
There are some internal-facing applications that are exclusively used by internal employees. These internal employees are all present in Microsoft Entra ID, so these internal-facing applications should directly authenticate against Microsoft Entra ID. These applications also use several internal APIs, that due to the sensitivity, should not be accessible by external users. However, they also use some of the more common APIs. These apps are only accessible via an internal DNS name, such as `https://app1.internal.example.com`.
44+
There are some internal-facing applications that are exclusively used by internal employees. These internal employees
45+
are all present in Microsoft Entra ID, so these internal-facing applications should directly authenticate against
46+
Microsoft Entra ID. These applications also use several internal APIs, that due to the sensitivity, should not be
47+
accessible by external users. However, they also use some of the more common APIs. These apps are only accessible via
48+
an internal DNS name, such as `https://app1.internal.example.com`.
3549

36-
There are also several public facing applications, that are used directly by customers. These users should be able to log in using their own identity, via providers like Google, Twitter, or others. This authentication process is handled by Duende IdentityServer. There is constant development ongoing on these applications and it's not uncommon for new applications to be introduced. There should be single sign-on across all these public facing applications. They are all available on the same domain name, but use path based routing to distinguish themselves, such as `https://app.example.com/app1`
50+
There are also several public facing applications, that are used directly by customers. These users should be able to
51+
log in using their own identity, via providers like Google, Twitter, or others. This authentication process is handled
52+
by Duende IdentityServer. There is constant development ongoing on these applications and it's not uncommon for new
53+
applications to be introduced. There should be single sign-on across all these public facing applications. They are
54+
all available on the same domain name, but use path based routing to distinguish themselves, such as
55+
`https://app.example.com/app1`
3756

38-
There is also a partner portal. This partner portal can only be accessed by employees of the partners. Each partner should be able to bring their own identity provider. This is implemented using the [Dynamic Providers](/identityserver/ui/login/dynamicproviders.md) feature of Duende IdentityServer.
57+
There is also a partner portal. This partner portal can only be accessed by employees of the partners. Each partner
58+
should be able to bring their own identity provider. This is implemented using the [Dynamic Providers](/identityserver/ui/login/dynamicproviders.md) feature of
59+
Duende IdentityServer.
3960

40-
This setup, with multiple frontends, each having different authentication requirements and different API surfaces, is now supported by the BFF.
61+
This setup, with multiple frontends, each having different authentication requirements and different API surfaces,
62+
is now supported by the BFF.
4163

42-
Each frontend can either rely on the global configuration or override (parts of) this configuration, such as the identity provider or the Client ID and Client Secret to use.
64+
Each frontend can either rely on the global configuration or override (parts of) this configuration, such as the
65+
identity provider or the Client ID and Client Secret to use.
4366

4467
It's also possible to dynamically add or remove frontends, without restarting the BFF host.
4568

@@ -51,7 +74,7 @@ To achieve this, the BFF automatically configures the ASP.NET Core pipeline:
5174

5275
![BFF Multi-Frontend Pipeline](../images/bff_multi_frontend_pipeline.svg)
5376

54-
1. `FrontendSelectionMiddleware` - This middleware performs the frontend selection by seeing which frontend's selection criteria best matches the incoming request route. It's possible to mix both path based routing origin based routing, so the most specific will be selected.
77+
1. `FrontendSelectionMiddleware` - This middleware performs the frontend selection by seeing which frontend's selection criteria best matches the incoming request route. It's possible to mix both path based routing and host based routing, so the most specific will be selected.
5578
2. `PathMappingMiddleware` - If you use path mapping, in the selected frontend, then it will automatically map the frontend's path so none of the subsequent middlewares know (or need to care) about this fact.
5679
3. `OpenIdCallbackMiddleware` - To dynamically perform the OpenID Connect authentication without explicitly adding each frontend as a scheme, we inject a middleware that will handle the OpenID Connect callbacks. This only kicks in for dynamic frontends.
5780
4. Your own applications logic is executed in this part of the pipeline. For example, calling `.UseAuthentication(), .UseRequestLogging()`, etc.

src/content/docs/bff/fundamentals/multi-frontend/configuration.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The configuration supports dynamic reloading (so any new frontend added / remove
5656
Example: `"/from-config"`
5757

5858
- `matchingHostHeader`
59-
The origin to match for this frontend.
59+
The host to match for this frontend.
6060
Example: `"https://localhost:5005"`
6161

6262
- `oidc`

src/content/docs/bff/fundamentals/multi-frontend/index.mdx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ To overcome this issue, a single BFF instance can support multiple frontends. Ea
2020
* Define its own OpenID Connect configuration
2121
* Define its own Cookie settings
2222
* Define its own API surface
23-
* Be identified either via path based routing and/or origin selection.
23+
* Be identified either via path based routing and/or host selection.
2424

2525
Adding additional frontends to the BFF has very little impact on the performance on the BFF itself, but keep in mind
2626
that the traffic for all the frontends is proxied through the BFF.
@@ -94,13 +94,18 @@ as via [Configuration](configuration.mdx).
9494

9595
## Frontend Selection
9696

97-
Each request to a frontend has to be uniquely defined by either its path, its origin or a combination of the two.
98-
If you specify neither, then it's considered the default frontend.
97+
Each request to a frontend has to be uniquely defined by either its path, its host or a combination of the two.
98+
If you specify neither, then it's considered the default frontend.
99+
100+
:::note
101+
With "host", we mean the combination of the schema (http/https), the domain (app1.example.com) and the port. The BFF
102+
frontend selection middleware uses the HTTP Host header to select a matching frontend.
103+
:::
99104

100105
Frontends are matched using the following algorithm:
101106

102-
1. **Selection by both origin and path:** If there is a frontend that matches both the origin AND has the most specific match to a path, it's selected.
103-
2. **Selection by origin only:** Then, if there is a frontend with only origins configured and it matches the path, it's selected.
107+
1. **Selection by both host and path:** If there is a frontend that matches both the host AND has the most specific match to a path, it's selected.
108+
2. **Selection by host only:** Then, if there is a frontend with only hosts configured and it matches the path, it's selected.
104109
3. **Selection by path only:** Then, if there is a frontend with a matching path specified, it's selected.
105110
4. **Default frontend:** Then, if there is a default frontend configured, it's selected.
106111

src/content/docs/bff/getting-started/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar:
66
label: Overview
77
---
88

9-
Currently, the most recent version is 4 (preview 2). If you're upgrading from a previous version, please check our [upgrade guides](/bff/upgrading).
9+
Currently, the most recent version is v4. If you're upgrading from a previous version, please check our [upgrade guides](/bff/upgrading).
1010

1111
If you're starting a new BFF project, consider the following startup guides:
1212

src/content/docs/bff/getting-started/multi-frontend.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ sidebar:
1111
import { Code } from "@astrojs/starlight/components";
1212
import { Tabs, TabItem } from "@astrojs/starlight/components";
1313

14-
Duende.BFF (Backend for Frontend) supports multiple frontends in a single BFF host. This is useful for scenarios where you want to serve several SPAs or frontend apps from the same backend, each with their own authentication and API proxying configuration.
14+
Duende.BFF (Backend for Frontend) supports multiple frontends in a single BFF host. This is useful for scenarios where
15+
you want to serve several SPAs or frontend apps from the same backend, each with their own authentication and API
16+
proxying configuration.
1517

1618
:::note
17-
Multi-frontend support is available in Duende.BFF v4 and later. The v3-style of wiring up BFF is not supported for this scenario.
19+
Multi-frontend support is available in Duende.BFF v4 and later. The v3-style of wiring up BFF is not supported for
20+
this scenario.
1821
:::
1922

2023
## Prerequisites
@@ -39,7 +42,8 @@ dotnet add package Duende.BFF
3942

4043
### 3. OpenID Connect Configuration
4144

42-
Configure OpenID Connect authentication for your BFF host. This is similar to the single frontend setup, but applies to all frontends unless overridden per frontend.
45+
Configure OpenID Connect authentication for your BFF host. This is similar to the single frontend setup, but applies
46+
to all frontends unless overridden per frontend.
4347

4448
```csharp
4549
// Program.cs

0 commit comments

Comments
 (0)