Skip to content

Commit 1f7ab4b

Browse files
committed
Enhance BFF documentation with updated migration details, improved claims enrichment examples, and new IUserEndpointClaimsEnricher implementation guidance
1 parent 5018afb commit 1f7ab4b

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

src/content/docs/bff/extensibility/management/user.mdx

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "BFF User Endpoint Extensibility"
3-
date: 2022-12-30 10:55:24
3+
date: 2026-01-20
44
sidebar:
55
label: "User"
66
order: 50
@@ -67,9 +67,12 @@ public override Task ProcessRequestAsync(HttpContext context, CancellationToken
6767

6868
### Enriching User Claims
6969

70-
There are several ways how you can enrich the claims for a specific user.
70+
There are several ways how you can enrich the claims for a specific user, depending on where the required data comes from.
7171

72-
The most robust way would be to implement a custom `IClaimsTransformation`.
72+
#### Claims Transformations
73+
74+
To enrich claims for a user, you can implement a custom `IClaimsTransformation`.
75+
Claims transformation executes as part of the authentication process.
7376

7477
```csharp
7578
services.AddScoped<IClaimsTransformation, CustomClaimsTransformer>();
@@ -92,4 +95,58 @@ public class CustomClaimsTransformer : IClaimsTransformation
9295

9396
See the [Claims Transformation](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/claims?view=aspnetcore-9.0) topic in the ASP.NET Core documentation for more information.
9497

98+
#### User Endporint Claims Enricher :badge[v4.0]
99+
100+
User claims can be enriched by implementing the `IUserEndpointClaimsEnricher` interface.
101+
This interface is specific to the user endpoint and runs after authentication.
102+
103+
Because this runs within the user endpoint request, you can access the current HTTP context to retrieve the user's access token.
104+
We recommend using the [`GetUserAccessTokenAsync`](/accesstokenmanagement/web-apps.mdx#http-context-extension-methods) extension method from `Duende.AccessTokenManagement.OpenIdConnect`, as it will automatically handle refreshing the token if it has expired.
105+
106+
```csharp
107+
// Program.cs
108+
builder.Services.AddTransient<IUserEndpointClaimsEnricher, CustomUserEndpointClaimsEnricher>();
109+
```
110+
111+
```csharp
112+
// CustomUserEndpointClaimsEnricher.cs
113+
using Duende.Bff;
114+
using Duende.Bff.Endpoints;
115+
using Duende.AccessTokenManagement.OpenIdConnect;
116+
using Microsoft.AspNetCore.Authentication;
117+
118+
public class CustomUserEndpointClaimsEnricher : IUserEndpointClaimsEnricher
119+
{
120+
private readonly IHttpContextAccessor _httpContextAccessor;
121+
122+
public CustomUserEndpointClaimsEnricher(IHttpContextAccessor httpContextAccessor)
123+
{
124+
_httpContextAccessor = httpContextAccessor;
125+
}
126+
127+
public async Task<IReadOnlyList<ClaimRecord>> EnrichClaimsAsync(
128+
AuthenticateResult authenticateResult,
129+
IReadOnlyList<ClaimRecord> claims,
130+
CancellationToken ct = default)
131+
{
132+
var newClaims = claims.ToList();
133+
134+
// Get the access token using the extension method
135+
// This will automatically handle token refreshing if needed
136+
var token = await _httpContextAccessor.HttpContext.GetUserAccessTokenAsync(cancellationToken: ct);
137+
138+
if (!string.IsNullOrEmpty(token.AccessToken))
139+
{
140+
// Call external API using the access token
141+
// ...
142+
}
143+
144+
// Add custom claims
145+
newClaims.Add(new ClaimRecord("custom_data", "some value"));
146+
147+
return newClaims;
148+
}
149+
}
150+
```
151+
95152
[1]: https://github.com/DuendeSoftware/products/tree/releases/bff/4.0.x/bff/src/Bff/Endpoints/Internal/DefaultUserEndpoint.cs

src/content/docs/bff/upgrading/bff-v3-to-v4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ If you have a custom implementation of `IUserSessionStore`, the interface has ch
8989
In all methods, the `string key` has been replaced with a strongly typed `UserSessionKey` struct, which contains the `PartitionKey` and `SessionId`:
9090

9191
* `PartitionKey` - Corresponds to the frontend name (or `ApplicationName` in V3).
92-
* `SessionId`: The user's session identifier.
92+
* `SessionId` - The user's session identifier.
9393

9494
```diff lang="csharp"
9595
public class MySessionStore : IUserSessionStore

0 commit comments

Comments
 (0)