Skip to content

Commit d7dfa3e

Browse files
authored
Merge pull request #751 from DuendeSoftware/mb/bff4spike
BFF v3 -> v4 guide
2 parents 1ff48ed + 175b5ce commit d7dfa3e

File tree

2 files changed

+130
-5
lines changed

2 files changed

+130
-5
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
title: "Duende BFF Security Framework v3.0 to v4.0"
3+
description: Guide for upgrading Duende BFF Security Framework from version 3.x to version 4.0, including migration steps for custom implementations and breaking changes.
4+
sidebar:
5+
label: v3.0 → v4.0
6+
order: 20
7+
---
8+
9+
Duende BFF Security Framework v4.0 is a significant release that includes:
10+
11+
* Multi-frontend support
12+
* OpenTelemetry support
13+
* Support for login prompts
14+
* Several fixes and improvements
15+
16+
The extensibility approach has been drastically changed, and many `virtual` methods containing implementation logic are now internal instead.
17+
18+
:::caution[Duende BFF Security Framework v4 is still in preview]
19+
The Duende BFF Security Framework v4 is still in preview (currently [preview 1](https://github.com/DuendeSoftware/products/releases/edit/bff-4.0.0-Preview1)).
20+
This version (and associated documentation) is still evolving.
21+
:::
22+
23+
## Upgrading
24+
25+
This release introduces many breaking changes. This upgrade guide covers cases where a breaking change was introduced.
26+
27+
### Remote APIs
28+
29+
The syntax for configuring remote APIs has changed slightly:
30+
31+
```diff lang="csharp" title="Program.cs"
32+
// Use a client credentials token
33+
app.MapRemoteBffApiEndpoint("/api/client-token", "https://localhost:5010")
34+
- .RequireAccessToken(TokenType.Client);
35+
+ .WithAccessToken(RequiredTokenType.Client);
36+
37+
// Use the client token only if the user is logged in
38+
app.MapRemoteBffApiEndpoint("/api/optional-user-token", "https://localhost:5010")
39+
- .WithOptionalUserAccessToken();
40+
+ .WithAccessToken(RequiredTokenType.UserOrNone);
41+
```
42+
43+
* The enum `TokenType` has been renamed to `RequiredTokenType`.
44+
* The methods to configure the token type have all been replaced with a new method `WithAccessToken()`
45+
* Requesting an optional access token should no longer be done by calling `WithOptionalUserAccessToken()`. Use `WithAccessToken(RequiredTokenType.UserOrNone)` instead.
46+
47+
### Configuring Token Types In YARP
48+
49+
The required token type configuration in YARP has also changed slightly. It uses the enum values from `RequiredTokenType`.
50+
51+
### Extending The BFF
52+
53+
#### Simplified Wireup Without Explicit Authentication Setup
54+
55+
The V3 style of wireup still works, but BFF V4 comes with a newer style of wireup:
56+
57+
```csharp
58+
services.AddBff()
59+
.WithDefaultOpenIdConnectOptions(options =>
60+
{
61+
options.Authority = "your authority";
62+
options.ClientId = "your client id";
63+
options.ClientSecret = "secret";
64+
// ... other OpenID Connect options.
65+
}
66+
.WithDefaultCookieOptions(options => {
67+
// The cookie options are automatically configured with recommended practices.
68+
// However, you can change the config here.
69+
};
70+
```
71+
72+
Adding this will automatically configure a Cookie and OpenID Connect flow.
73+
74+
#### Adding Multiple Frontends
75+
76+
You can statically add a list of frontends by calling the `AddFrontends` method.
77+
78+
```csharp
79+
.AddFrontends(
80+
new BffFrontend(BffFrontendName.Parse("default-frontend"))
81+
.WithIndexHtmlUrl(new Uri("https://localhost:5005/static/index.html")),
82+
83+
new BffFrontend(BffFrontendName.Parse("with-path"))
84+
.WithOpenIdConnectOptions(opt =>
85+
{
86+
opt.ClientId = "bff.multi-frontend.with-path";
87+
opt.ClientSecret = "secret";
88+
})
89+
.WithIndexHtmlUrl(new Uri("https://localhost:5005/static/index.html"))
90+
.MappedToPath(LocalPath.Parse("/with-path")),
91+
92+
new BffFrontend(BffFrontendName.Parse("with-domain"))
93+
.WithOpenIdConnectOptions(opt =>
94+
{
95+
opt.ClientId = "bff.multi-frontend.with-domain";
96+
opt.ClientSecret = "secret";
97+
})
98+
.WithIndexHtmlUrl(new Uri("https://localhost:5005/static/index.html"))
99+
.MappedToOrigin(Origin.Parse("https://app1.localhost:5005"))
100+
.WithRemoteApis(
101+
new RemoteApi(LocalPath.Parse("/api/user-token"), new Uri("https://localhost:5010")),
102+
new RemoteApi(LocalPath.Parse("/api/client-token"), new Uri("https://localhost:5010"))
103+
)
104+
```
105+
106+
#### Loading Configuration From `IConfiguration`
107+
108+
Loading configuration, including OpenID Connect configuration from `IConfiguration` is now supported:
109+
110+
```csharp
111+
services.AddBff().LoadConfiguration(bffConfig);
112+
```
113+
114+
This enables you to configure your OpenID Connect options, including secrets, and configure the list of frontends. This also adds a file watcher, to automatically add / remove frontends from the config file.
115+
116+
See the type `BffConfiguration` to see what settings can be configured.
117+
118+
#### Index HTML Retrieval
119+
120+
It's fairly common to deploy your application in such a way to have the BFF be the first entrypoint for your application. It should serve an index.html that will bootstrap your frontend. However, your static content should be loaded from a CDN.
121+
122+
If you publish your frontend code to a cdn with absolute paths (for example by specifying a base path in your vite config), then all static content is loaded directly from the CDN.
123+
124+
You can configure the location of your `index.html` by specifying:
125+
126+
```csharp
127+
.WithIndexHtmlUrl(new Uri("https://localhost:5005/static/index.html"))
128+
```

src/content/docs/bff/upgrading/index.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Upgrading BFF Security Framework"
3-
description: "Guide for upgrading Duende.BFF versions, including NuGet package updates and database schema migrations"
3+
description: "Guide for upgrading Duende.BFF versions, including NuGet package updates"
44
date: 2020-09-10T08:22:12+02:00
55
sidebar:
66
order: 1
@@ -15,10 +15,7 @@ redirect_from:
1515

1616
import { CardGrid, LinkCard } from "@astrojs/starlight/components";
1717

18-
Upgrading to a new Duende.BFF version is done by updating the NuGet package and handling any breaking
19-
changes. Some updates contain changes to the stores used by IdentityServer that requires database
20-
schema updates. If you are using our Entity Framework based stores we recommend using Entity Framework
21-
Migrations.
18+
Upgrading to a new Duende.BFF version is done by updating the NuGet package and handling any breaking changes.
2219

2320
<CardGrid>
2421
<LinkCard

0 commit comments

Comments
 (0)