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/extensibility/http-forwarder.md
+91-39Lines changed: 91 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ You can customize the HTTP forwarder behavior in two ways
17
17
* provide a customized HTTP client for outgoing calls
18
18
* provide custom request/response transformation
19
19
20
-
###Custom HTTP clients
20
+
## Custom HTTP clients
21
21
By default, Duende.BFF will create and cache an HTTP client per configured route or local path.
22
22
23
23
This invoker is set up like this:
@@ -32,64 +32,116 @@ var client = new HttpMessageInvoker(new SocketsHttpHandler
32
32
});
33
33
```
34
34
35
-
If you want to customize the HTTP client for specific paths, you can either implement the *IHttpMessageInvokerFactory* interface or derive from the *DefaultHttpMessageInvokerFactory*, e.g.:
35
+
If you want to customize the HTTP client you can either implement the *IForwarderHttpClientFactory* interface, e.g.:
//You can also add custom transformers, such as this one that adds an additional header
88
+
context.AddRequestHeader("custom", "with value");
89
+
90
+
});
91
+
92
+
```
93
+
94
+
The default transformbuilder performs these transforms:
95
+
96
+
```csharp
97
+
context.AddRequestHeaderRemove("Cookie");
98
+
context.AddPathRemovePrefix(localPath);
99
+
context.AddBffAccessToken(localPath);
100
+
```
101
+
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)
103
+
104
+
### Changing the default transformer.
105
+
106
+
You can change the default transformer builder delegate by registering one in the services collection:
// 100 ms timeout, which is not too short that the normal process might fail,
140
+
// but not too long that the test will take forever
141
+
ActivityTimeout=TimeSpan.FromMilliseconds(100)
142
+
});
143
+
89
144
```
90
145
91
-
...or derive from the *DefaultHttpTransformerFactory*.
92
146
93
-
:::note
94
-
The transformations are based on YARP's transform library and are extensible. See [here](https://microsoft.github.io/reverse-proxy/articles/transforms.html) for a full list of built-in transforms.
The back-channel logout endpoint has several extensibility points organized into two interfaces and their default implementations. The *IBackChannelLogoutService* 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*.
16
16
17
17
## Request Processing
18
-
You can add custom logic to the endpoint by implementing the *IBackChannelLogoutService* or by extending its default implementation (*Duende.Bff.DefaultBackChannelLogoutService*). In most cases, extending the default implementation is preferred, as it has several virtual methods that can be overridden to customize particular aspects of how the request is processed.
18
+
You can add custom logic to the endpoint by implementing the *IBackChannelLogoutEndpoint*.
19
19
20
20
*ProcessRequestAsync* is the top level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
Validation of the incoming request can be customized by overriding one of several virtual methods in the *DefaultBackChannelLogoutService*. *GetTokenValidationParameters* allows you to specify the *[TokenValidationParameters](https://learn.microsoft.com/en-us/dotnet/API/microsoft.identitymodel.tokens.tokenvalidationparameters?view=azure-dotnet)* used to validate the incoming logout token. The default implementation creates token validation parameters based on the authentication scheme's configuration. Your override could begin by calling the base method and then make changes to those parameters or completely customize how token validation parameters are created. For example:
If you need more control over the validation of the logout token, you can override *ValidateJwt*. The default implementation of *ValidateJwt* validates the token and produces a *ClaimsIdentity* using a *[JsonWebTokenHandler](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/wiki/ValidatingTokens)* and the token validation parameters returned from *GetTokenValidationParameters*. Your override could call the base method and then manipulate this *ClaimsIdentity* or add a completely custom method for producing the *ClaimsIdentity* from the logout token.
54
-
55
-
*ValidateLogoutTokenAsync* is the coarsest-grained validation method. It is responsible for validating the incoming logout token and determining if logout should proceed, based on claims in the token. It returns a *ClaimsIdentity* if logout should proceed or null if it should not. Your override could prevent logout in certain circumstances by returning null. For example:
// For example, prevent logout based on certain conditions
66
-
if(identity?.FindFirst("sub")?.Value=="12345")
67
-
{
68
-
returnnull;
69
-
}
70
-
else
71
-
{
72
-
returnidentity;
73
-
}
74
-
}
75
-
}
76
-
```
77
32
78
33
## Session Revocation
79
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*.
The BFF diagnostics endpoint can be customized by implementing the *IDiagnosticsService* or by extending *DefaultDiagnosticsService*, its default implementation.
15
+
The BFF diagnostics endpoint can be customized by implementing the *IDiagnosticsEndpoint*.
16
16
17
17
## Request Processing
18
18
*ProcessRequestAsync* is the top level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
19
19
20
20
For example, you could take whatever actions you need before normal processing of the request like this:
You can add your own implementation by overriding the default after calling *AddBff()*.
29
29
30
-
The management endpoint services all inherit from the *IBffEndpointService*, 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.
The BFF login endpoint has extensibility points in two interfaces. The *ILoginService* 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.
16
16
17
17
## Request Processing
18
18
*ProcessRequestAsync* is the top level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
19
19
20
20
For example, you could take whatever actions you need before normal processing of the request like this:
The BFF logout endpoint has extensibility points in two interfaces. The *ILogoutService* 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 logout endpoint is safe to use.
15
+
The BFF logout endpoint has extensibility points in two interfaces. The *ILogoutEndpoint* 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 logout endpoint is safe to use.
16
16
17
17
## Request Processing
18
18
*ProcessRequestAsync* is the top level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
19
19
20
20
For example, you could take whatever actions you need before normal processing of the request like this:
The BFF silent login callback endpoint can be customized by implementing the *ISilentLoginCallbackService* or by extending *DefaultSilentLoginCallbackService*, its default implementation.
15
+
The BFF silent login callback endpoint can be customized by implementing the *ISilentLoginCallbackEndpoint*.
16
16
17
17
## Request Processing
18
18
*ProcessRequestAsync* is the top level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
19
19
20
20
For example, you could take whatever actions you need before normal processing of the request like this:
The BFF silent login endpoint can be customized by implementing the *ISilentLoginService* or by extending *DefaultSilentLoginService*, its default implementation.
15
+
The BFF silent login endpoint can be customized by implementing the *ISilentLoginEndpoint*.
16
16
17
17
## Request Processing
18
18
*ProcessRequestAsync* is the top level function called in the endpoint service and can be used to add arbitrary logic to the endpoint.
19
19
20
20
For example, you could take whatever actions you need before normal processing of the request like this:
0 commit comments