Skip to content
Livestream: Demystifying Authentication in ASP.NET Core with Tore Nestenius. Register Now!

BFF User Endpoint Extensibility

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

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

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

public Task ProcessRequestAsync(HttpContext context, CancellationToken ct)
{
// Custom logic here
}

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.