You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/bff/architecture/multi-frontend.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,4 +62,39 @@ After your application's logic is executed, there are two middlewares registered
62
62
63
63
6.`ProxyIndexMiddleware` - If configured, this proxy the `index.html` to start the browser based app.
64
64
65
+
If you don't want this automatic mapping of BFF middleware, you can turn it off using `BffOptions.AutomaticallyRegisterBffMiddleware`. Please note then you're responsible for manually adding the middlewares:
66
+
67
+
```csharp
68
+
varapp=builder.Build();
69
+
70
+
app.UseBffFrontendSelection();
71
+
app.UseBffPathMapping();
72
+
app.UseBffOpenIdCallbacks();
73
+
74
+
// Todo: your custom middleware goes here:
75
+
app.UseRouting();
76
+
app.UseBff();
77
+
78
+
// Only add this if you want to proxy to remote api's.
79
+
app.UseBffRemoteRoutes();
80
+
81
+
app.MapBffManagementEndpoints();
82
+
app.UseBffIndexPages();
83
+
84
+
app.Run();
85
+
```
86
+
87
+
## Authentication architecture
88
+
89
+
When you use multiple frontends, you can't rely on [manual authentication configuration](../fundamentals/session/handlers.mdx#manually-configuring-authentication). This is because each frontend requires it's own scheme, and potentially it's own OpenID Connect and Cookie configuration.
90
+
91
+
The BFF registers a dynamic authentication scheme, which automatically configures the OpenID Connect and Cookie Scheme's on behalf of the frontends. It does this using a custom `AuthenticationSchemeProvider` called `BffAuthenticationSchemeProvider` to return appropriate authentication schemes for each frontend.
92
+
93
+
The BFF will register two schemes:
94
+
* 'duende-bff-oidc'.
95
+
* 'duende-bff-cookie'.
96
+
97
+
Then, if there are no default authentication schemes registered, it will register 'duende_bff_cookie' schemes as the `AuthenticationOptions.DefaultScheme`, and 'duende_bff_oidc' as the `AuthenticationOptions.DefaultAuthenticateScheme` and `AuthenticationOptions.DefaultSignOutScheme`. This will ensure that calls to `Authenticate()` or `Signout()` will use the appropriate schemes.
98
+
99
+
If you're using multiple frontends, then the BFF will create dynamic schemes with the following signature: 'duende_bff_oidc_[frontendname]' and 'duende_bff_cookie_[frontendname]'. This ensures that every frontend can use it's own OpenID Connect and Cookie settings.
Copy file name to clipboardExpand all lines: src/content/docs/bff/fundamentals/multi-frontend/index.mdx
+68Lines changed: 68 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,74 @@ To overcome this issue, a single BFF instance can support multiple frontends. Ea
25
25
Adding additional frontends to the BFF has very little impact on the performance on the BFF itself, but keep in mind
26
26
that the traffic for all the frontends is proxied through the bff.
27
27
28
+
## Authentication configuration
29
+
30
+
31
+
When you use multiple frontends, you can't rely on [manual authentication configuration](../fundamentals/session/handlers.mdx#manually-configuring-authentication).
32
+
This is because each frontend requires it's own scheme, and potentially it's own OpenID Connect and Cookie configuration.
33
+
34
+
Instead, you should rely on [automatic authentication configuration](../fundamentals/session/handlers.mdx#automatic-authentication-configuration).
35
+
36
+
Below is an example on how to configure multiple frontends.
37
+
38
+
```csharp
39
+
varbffBuilder=builder.Services
40
+
.AddBff();
41
+
42
+
bffBuilder
43
+
.ConfigureOpenIdConnect(options=>
44
+
{
45
+
// These are the default values for all frontends.
By default, ASP.NET Core's cookie handler will store all user session data in a protected cookie. This works very well unless cookie size or revocation becomes an issue.
15
18
@@ -47,34 +50,76 @@ builder.Services.AddBff()
47
50
Most datastores that you might use with Entity Framework use a schema to define the structure of their data. *Duende.BFF.EntityFramework* doesn't make any assumptions about the underlying datastore, how (or indeed even if) it defines its schema, or how schema changes are managed by your organization. For these reasons, Duende does not directly support database creation, schema changes, or data migration by publishing database scripts. You are expected to manage your database in the way your organization sees fit. Using EF migrations is one possible approach to that, which Duende facilitates by publishing entity classes in each version of *Duende.BFF.EntityFramework*. An example project that uses those entities to create migrations is [here](https://github.com/DuendeSoftware/products/tree/main/bff/migrations/UserSessionDb).
48
51
49
52
## Session Store Cleanup
50
-
51
53
Added in v1.2.0.
52
54
53
55
Abandoned sessions will remain in the store unless something removes the stale entries.
54
-
If you wish to have such sessions cleaned up periodically, then you can configure the *EnableSessionCleanup* and *SessionCleanupInterval* options:
If you wish to have such sessions cleaned up periodically, then you can add the session cleanup host and configure the *SessionCleanupInterval* options:
This requires an implementation of [*IUserSessionStoreCleanup*](/bff/extensibility/sessions#user-session-store-cleanup) in the ASP.NET Core service provider.
72
+
73
+
If using Entity Framework Core, then the *IUserSessionStoreCleanup* implementation is provided for you when you use *AddEntityFrameworkServerSideSessions*.
74
+
You can then add the `SessionCleanupBackgroundProcess`:
75
+
76
+
```csharp
77
+
varcn=_configuration.GetConnectionString("db");
78
+
79
+
builder.Services.AddBff()
80
+
.AddEntityFrameworkServerSideSessions(options=>
81
+
{
82
+
options.UseSqlServer(cn);
83
+
})
84
+
.AddSessionCleanupBackgroundProcess();
85
+
```
86
+
:::note
87
+
In V4, we changed how you enable session cleanup. We no longer automatically register the session cleanup hosted service. This has to be done manually.
88
+
In a loadbalanced environment, you can choose to run the cleanup job on all instances the BFF. However, you can also decide to
89
+
spin up a separate host that's responsible for background jobs such as this cleanup job.
90
+
:::
91
+
92
+
</TabItem>
93
+
<TabItemlabel="V3">
94
+
95
+
If you wish to have such sessions cleaned up periodically, then you can configure the *EnableSessionCleanup* and *SessionCleanupInterval* options:
This requires an implementation of [*IUserSessionStoreCleanup*](/bff/extensibility/sessions#user-session-store-cleanup) in the ASP.NET Core service provider.
106
+
107
+
If using Entity Framework Core, then the *IUserSessionStoreCleanup* implementation is provided for you when you use *AddEntityFrameworkServerSideSessions*.
108
+
Just enable session cleanup:
109
+
110
+
```csharp
111
+
varcn=_configuration.GetConnectionString("db");
112
+
113
+
builder.Services.AddBff(options=>
114
+
{
115
+
options.EnableSessionCleanup=true;
116
+
})
117
+
.AddEntityFrameworkServerSideSessions(options=>
118
+
{
119
+
options.UseSqlServer(cn);
120
+
});
121
+
```
122
+
123
+
</TabItem>
124
+
</Tabs>
63
125
64
-
This requires an implementation of [*IUserSessionStoreCleanup*](/bff/extensibility/sessions#user-session-store-cleanup) in the ASP.NET Core service provider.
65
-
66
-
If using Entity Framework Core, then the *IUserSessionStoreCleanup* implementation is provided for you when you use *AddEntityFrameworkServerSideSessions*.
0 commit comments