Skip to content

Commit 89802ed

Browse files
committed
Apply suggestions from code review
1 parent fe72572 commit 89802ed

File tree

23 files changed

+215
-216
lines changed

23 files changed

+215
-216
lines changed

src/content/docs/bff/architecture/index.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ functions:
2222
* Server-side Token Management
2323
* Blazor support with unified authentication state management across rendering modes.
2424

25-
## Authentiation flow
25+
## Authentication Flow
2626

27-
The following diagram shows how the BFF protects browser based applications.
27+
The following diagram shows how the BFF protects browser-based applications:
2828

2929
![BFF Security Framework Architecture Overview](../images/bff_application_architecture.svg)
3030

3131

32-
* **Authentication flows**: The server handles the authentication flows. There are specific endpoints for login / logout. While the browser is involved with these authentication flows, because the user is redirected to and from the identity provider, the actual browser based application will never see the authentication tokens. These are exchanged for a code on the server only.
33-
* **Cookies**: After successful authentication, a cookie is added. This cookie protects all subsequent calls to the apis. When using this type of authentication, **CSRF protection** is very important.
34-
* **Access to apis**: The BFF can expose embedded apis (which are embedded in the BFF itself) or proxy calls to remote api's (which is more common in a microservice environment). While proxying, it will exchange the authentication cookie for an access token.
35-
* **Session Management**: The BFF can manage the users session. This can either be cookie based session management or storage based session management.
32+
* **Authentication flows**: The server handles the authentication flows. There are specific endpoints for login / logout. While the browser is involved with these authentication flows, because the user is redirected to and from the identity provider, the browser-based application will never see the authentication tokens. These are exchanged for a code on the server only.
33+
* **Cookies**: After successful authentication, a cookie is added. This cookie protects all subsequent calls to the APIs. When using this type of authentication, **CSRF protection** is very important.
34+
* **Access to APIs**: The BFF can expose embedded APIs (which are hosted by the BFF itself) or proxy calls to remote APIs (which is more common in a microservice environment). While proxying, it will exchange the authentication cookie for an access token.
35+
* **Session Management**: The BFF can manage the users session. This can either be cookie-based session management or storage-based session management.
3636

3737

3838
## Internals
3939
Duende.BFF builds on widely used tools and frameworks, including ASP.NET Core's OpenID Connect and cookie authentication
40-
handlers, YARP, and Duende.AccessTokenManagement. Duende.BFF combines these tools and adds additional security and
40+
handlers, YARP, and [Duende.AccessTokenManagement](/accesstokenmanagement/index.mdx). Duende.BFF combines these tools and adds additional security and
4141
application features that are useful with a BFF architecture so that you can focus on providing application logic
4242
instead of security logic:
4343

@@ -50,7 +50,7 @@ contributors to this library, we think it is a well implemented and flexible imp
5050

5151
### ASP.NET Cookie Handler
5252

53-
Duende.BFF uses ASP.NET's Cookie handler for session management. The Cookie handler provides a claims-based identity to
53+
Duende.BFF uses ASP.NET's Cookie handler for session management. The cookie handler provides a claims-based identity to
5454
the application persisted in a digitally signed and encrypted cookie that is protected with modern cookie security
5555
features, including the Secure, HttpOnly and SameSite attributes. The handler also provides absolute and sliding session
5656
support, and has a flexible extensibility model, which Duende.BFF uses to

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The Duende BFF V4 library doesn't ship with an abstraction to store or read fron
2929

3030
## A Typical Example
3131

32-
Consider an enterprise that hosts multiple browser based applications. Each of these applications is developed by a separate team and as such, has it's own deployment schedule.
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.
3333

3434
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`.
3535

@@ -60,9 +60,9 @@ After your application's logic is executed, there are two middlewares registered
6060

6161
5. `MapRemoteRoutesMiddleware` - This will handle any configured remote routes. Note, it will not handle plain YARP calls, only routes that are specifically added to a frontend.
6262

63-
6. `ProxyIndexMiddleware` - If configured, this proxy the `index.html` to start the browser based app.
63+
6. `ProxyIndexMiddleware` - If configured, this proxies the `index.html` to start the browser based app.
6464

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:
65+
If you don't want this automatic mapping of BFF middleware, you can turn it off using `BffOptions.AutomaticallyRegisterBffMiddleware`. When doing so, you'll need to manually register and add the middlewares:
6666

6767
```csharp
6868
var app = builder.Build();
@@ -71,11 +71,11 @@ app.UseBffFrontendSelection();
7171
app.UseBffPathMapping();
7272
app.UseBffOpenIdCallbacks();
7373

74-
// Todo: your custom middleware goes here:
74+
// TODO: your custom middleware goes here
7575
app.UseRouting();
7676
app.UseBff();
7777

78-
// Only add this if you want to proxy to remote api's.
78+
// NOTE: Only add this if you want to proxy remote APIs.
7979
app.UseBffRemoteRoutes();
8080

8181
app.MapBffManagementEndpoints();
@@ -84,17 +84,17 @@ app.UseBffIndexPages();
8484
app.Run();
8585
```
8686

87-
## Authentication architecture
87+
## Authentication Architecture
8888

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.
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 its own scheme, and potentially its own OpenID Connect and Cookie configuration.
9090

9191
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.
9292

9393
The BFF will register two schemes:
94-
* 'duende-bff-oidc'.
95-
* 'duende-bff-cookie'.
94+
* `duende-bff-oidc`
95+
* `duende-bff-cookie`
9696

9797
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.
9898

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.
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 its own OpenID Connect and Cookie settings.
100100

src/content/docs/bff/extensibility/http-forwarder.md

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ You can customize the HTTP forwarder behavior in two ways
1717
* provide a customized HTTP client for outgoing calls
1818
* provide custom request/response transformation
1919

20-
## Custom HTTP clients
20+
## Custom HTTP Clients
21+
2122
By default, Duende.BFF will create and cache an HTTP client per configured route or local path.
2223

2324
This invoker is set up like this:
@@ -32,12 +33,12 @@ var client = new HttpMessageInvoker(new SocketsHttpHandler
3233
});
3334
```
3435

35-
If you want to customize the HTTP client you can either implement the *IForwarderHttpClientFactory* interface, e.g.:
36+
If you want to customize the HTTP client you can implement the `IForwarderHttpClientFactory` interface, e.g.:
3637

3738
```cs
3839
public class MyInvokerFactory : IForwarderHttpClientFactory
3940
{
40-
public public HttpMessageInvoker CreateClient(ForwarderHttpClientContext context)
41+
public HttpMessageInvoker CreateClient(ForwarderHttpClientContext context)
4142
{
4243
return Clients.GetOrAdd(localPath, (key) =>
4344
{
@@ -62,46 +63,44 @@ public class MyInvokerFactory : IForwarderHttpClientFactory
6263
services.AddSingleton<IForwarderHttpClientFactory, MyInvokerFactory>();
6364
```
6465

65-
## Custom transformations when using Direct Forwarding
66+
## Custom Transformations When Using Direct Forwarding
6667

6768
The method MapRemoteBffApiEndpoint uses default transformations that:
6869
* removes the cookie header from the forwarded request
69-
* removes local path from from the forwarded request
70+
* removes local path from the forwarded request
7071
* Adds the access token to the original request
7172

7273
If you wish to change or extend this behavior, you can do this for a single mapped endpoint
73-
or for all mapped api endpoints.
74+
or for all mapped API endpoints.
7475

75-
### Changing the transformer for a single mapped endpoint
76+
### Changing The Transformer For A Single Mapped Endpoint
7677

77-
This code block shows an example how you can extend the default transformers with an additional custom
78+
This code block shows an example how of you can extend the default transformers with an additional custom
7879
transform.
7980

8081
```csharp
81-
8282
app.MapRemoteBffApiEndpoint("/local", new Uri("https://target/"), context => {
8383

8484
// If you want to extend the existing behavior, then you must call the default builder:
8585
DefaultBffYarpTransformerBuilders.DirectProxyWithAccessToken("/local", context);
8686

87-
//You can also add custom transformers, such as this one that adds an additional header
87+
// You can also add custom transformers, such as this one that adds an additional header
8888
context.AddRequestHeader("custom", "with value");
8989

9090
});
91-
9291
```
9392

94-
The default transformbuilder performs these transforms:
93+
The default transform builder performs these transforms:
9594

9695
```csharp
9796
context.AddRequestHeaderRemove("Cookie");
9897
context.AddPathRemovePrefix(localPath);
9998
context.AddBffAccessToken(localPath);
10099
```
101100

102-
For more information, also see the [yarp documentation on transforms](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/yarp/transforms?view=aspnetcore-9.0)
101+
For more information, also see the [YARP documentation on transforms](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/yarp/transforms?view=aspnetcore-9.0)
103102

104-
### Changing the default transformer.
103+
### Changing The Default Transformer
105104

106105
You can change the default transformer builder delegate by registering one in the services collection:
107106

@@ -111,22 +110,21 @@ BffYarpTransformBuilder builder = (localPath, context) => {
111110
// If you want to extend the existing behavior, then you must call the default builder:
112111
DefaultBffYarpTransformerBuilders.DirectProxyWithAccessToken(localpath, context);
113112

114-
//You can also add custom transformers, such as this one that adds an additional header
113+
// You can also add custom transformers, such as this one that adds an additional header
115114
context.AddResponseHeader("added-by-custom-default-transform", "some-value");
116115

117116
};
118117

119118
services.AddSingleton<BffYarpTransformBuilder>(builder);
120119
```
121120

122-
## Changing the Forwarder Request Config
121+
## Changing The Forwarder Request Configuration
123122

124-
You an also modify the forwarder request config, either globally or per mapped path.
123+
You an also modify the forwarder request configuration, either globally or per mapped path.
125124
This can be useful if you want to tweak things like activity timeouts.
126125

127126
```csharp
128-
129-
// Register a forwarder config globally.
127+
// Register a forwarder config globally:
130128
services.AddSingleton(new ForwarderRequestConfig()
131129
{
132130
ActivityTimeout = TimeSpan.FromMilliseconds(100)
@@ -140,7 +138,6 @@ app.MapRemoteBffApiEndpoint("/local", new Uri("https://target/"),
140138
// but not too long that the test will take forever
141139
ActivityTimeout = TimeSpan.FromMilliseconds(100)
142140
});
143-
144141
```
145142

146143

src/content/docs/bff/extensibility/management/back-channel-logout.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ redirect_from:
1212
- /identityserver/v7/bff/extensibility/management/back-channel-logout/
1313
---
1414

15-
The back-channel logout endpoint has several extensibility points organized into two interfaces. The *IBackChannelLogoutEndpoint* is the top level abstraction that processes requests to the endpoint. This service can be used to add custom request processing logic or to change how it validates incoming requests. When the back-channel logout endpoint receives a valid request, it revokes sessions using the *ISessionRevocationService*.
15+
The back-channel logout endpoint has several extensibility points organized into two interfaces. The `IBackChannelLogoutEndpoint` is the top-level abstraction that processes requests to the endpoint. This service can be used to add custom request processing logic or to change how it validates incoming requests. When the back-channel logout endpoint receives a valid request, it revokes sessions using the `ISessionRevocationService`.
1616

1717
## Request Processing
18-
You can add custom logic to the endpoint by implementing the *IBackChannelLogoutEndpoint* .
18+
You can add custom logic to the endpoint by implementing the `IBackChannelLogoutEndpoint` .
1919

20-
*ProcessRequestAsync* is the top level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
20+
`ProcessRequestAsync` is the top-level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
2121

2222
```csharp
2323
public class CustomizedBackChannelLogoutService : IBackChannelLogoutEndpoint
@@ -31,4 +31,4 @@ public class CustomizedBackChannelLogoutService : IBackChannelLogoutEndpoint
3131

3232

3333
## Session Revocation
34-
The back-channel logout service will call the registered session revocation service to revoke the user session when it receives a valid logout token. To customize the revocation process, implement the *ISessionRevocationService*.
34+
The back-channel logout service will call the registered session revocation service to revoke the user session when it receives a valid logout token. To customize the revocation process, implement the `ISessionRevocationService`.

src/content/docs/bff/extensibility/management/diagnostics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ redirect_from:
1212
- /identityserver/v7/bff/extensibility/management/diagnostics/
1313
---
1414

15-
The BFF diagnostics endpoint can be customized by implementing the *IDiagnosticsEndpoint*.
15+
The BFF diagnostics endpoint can be customized by implementing the `IDiagnosticsEndpoint`.
1616

1717
## Request Processing
18-
*ProcessRequestAsync* is the top level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
18+
`ProcessRequestAsync` is the top-level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
1919

2020
For example, you could take whatever actions you need before normal processing of the request like this:
2121

src/content/docs/bff/extensibility/management/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ builder.Services.AddTransient<IBackchannelLogoutService, DefaultBackchannelLogou
2525
builder.Services.AddTransient<IDiagnosticsService, DefaultDiagnosticsService>();
2626
```
2727

28-
You can add your own implementation by overriding the default after calling *AddBff()*.
28+
You can add your own implementation by overriding the default after calling `AddBff()`.
2929

30-
The management endpoint services all inherit from the *IBffEndpointEndpoint*, which provides a general-purpose mechanism to add custom logic to the endpoints.
30+
The management endpoint services all inherit from the `IBffEndpointEndpoint`, which provides a general-purpose mechanism to add custom logic to the endpoints.
3131

3232
```csharp
3333
public interface IBffEndpointService
@@ -36,6 +36,6 @@ public interface IBffEndpointService
3636
}
3737
```
3838

39-
None of the endpoint services contain additional members beyond *ProcessRequestAsync*.
39+
None of the endpoint services contain additional members beyond `ProcessRequestAsync`.
4040

4141
You can customize the behavior of the endpoints either by implementing the appropriate interface or by extending the default implementation of that interface. In many cases, extending the default implementation is preferred, as this allows you to keep most of the default behavior by calling the base *ProcessRequestAsync* from your derived class. Several of the default endpoint service implementations also define virtual methods that can be overridden to customize their behavior with more granularity.

src/content/docs/bff/extensibility/management/login.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ redirect_from:
1212
- /identityserver/v7/bff/extensibility/management/login/
1313
---
1414

15-
The BFF login endpoint has extensibility points in two interfaces. The *ILoginEndpoint* is the top level abstraction that processes requests to the endpoint. This service can be used to add custom request processing logic. The *IReturnUrlValidator* ensures that the *returnUrl* parameter passed to the login endpoint is safe to use.
15+
The BFF login endpoint has extensibility points in two interfaces. The `ILoginEndpoint` is the top-level abstraction that processes requests to the endpoint. This service can be used to add custom request processing logic. The `IReturnUrlValidator` ensures that the `returnUrl` parameter passed to the login endpoint is safe to use.
1616

1717
## Request Processing
18-
*ProcessRequestAsync* is the top level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
18+
19+
`ProcessRequestAsync` is the top-level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
1920

2021
For example, you could take whatever actions you need before normal processing of the request like this:
2122

@@ -29,4 +30,5 @@ public Task ProcessRequestAsync(HttpContext context, CancellationToken ct)
2930
```
3031

3132
## Return URL Validation
32-
To prevent open redirector attacks, the *returnUrl* parameter to the login endpoint must be validated. You can customize this validation by implementing the *IReturnUrlValidator* interface. The default implementation enforces that return urls are local.
33+
34+
To prevent open redirector attacks, the `returnUrl` parameter to the login endpoint must be validated. You can customize this validation by implementing the `IReturnUrlValidator` interface. The default implementation enforces that return URLs are local.

0 commit comments

Comments
 (0)