Skip to content

BFF User Endpoint Extensibility

The BFF user endpoint can be customized by implementing the IUserEndpoint.

You can customize the behavior of the user endpoint by implementing the ProcessRequestAsync method of the IUserEndpoint interface. The default implementation can serve as a starting point for your own implementation.

If you want to extend the default behavior of the user endpoint, you can instead add a custom endpoint and call the original endpoint implementation:

Program.cs
var bffOptions = app.Services.GetRequiredService<IOptions<BffOptions>>().Value;
app.MapGet(bffOptions.UserPath, async (HttpContext context, CancellationToken ct) =>
{
// Custom logic before calling the original endpoint implementation
var endpointProcessor = context.RequestServices.GetRequiredService<IUserEndpoint>();
await endpointProcessor.ProcessRequestAsync(context, ct);
// Custom logic after calling the original endpoint implementation
});

There are several ways how you can enrich the claims for a specific user.

The most robust way would be to implement a custom IClaimsTransformation.

services.AddScoped<IClaimsTransformation, CustomClaimsTransformer>();
public class CustomClaimsTransformer : IClaimsTransformation
{
public Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
{
var identity = (ClaimsIdentity)principal.Identity;
if (!identity.HasClaim(c => c.Type == "custom_claim"))
{
identity.AddClaim(new Claim("custom_claim", "your_value"));
}
return Task.FromResult(principal);
}
}

See the Claims Transformation topic in the ASP.NET Core documentation for more information.