Note:
There were minor issues with this release, please use Duende Access Token Management 4.1.0 Preview 2 instead.
This is a preview release which contains a new feature and support for .NET 10 RC2.
Enhancements
- .NET 10 RC1 support by @damianh in #211
- Remove unused package references by @damianh in #242
- .NET 10 RC2 by @damianh in #277
Introduction of Token Request Customization
Previously there was no ability to modify the token request parameters before a request is made to retrieve a token. This restricted the ability for users to scope tokens based on a particular request context.
We have provided the above mentioned capability by introducing an ITokenRequestCustomizer
. Given the HttpRequestMessage
as well as the TokenRequestParameters
the user can customize the TokenRequestParameters
that will be used to make the token request.
ITokenRequestCustomizer
interface - Service for customizing token request parameters based on HTTP request context- New overloads for token handler extension methods that accept an optional
ITokenRequestCustomizer
parameter:AddClientCredentialsTokenHandler(ITokenRequestCustomizer?, ClientCredentialsClientName)
AddClientAccessTokenHandler(ITokenRequestCustomizer?, UserTokenRequestParameters?)
AddUserAccessTokenHandler(ITokenRequestCustomizer?, UserTokenRequestParameters?)
Example usage:
public class ByPartitionIdTokenRequestCustomizer : ITokenRequestCustomizer
{
public Task<TokenRequestParameters> Customize(
HttpRequestMessage httpRequest,
TokenRequestParameters baseParameters,
CancellationToken cancellationToken = default)
{
var partitionId = httpRequest.Headers.GetValues("X-Partition-Id").FirstOrDefault();
var customizedParams = baseParameters with
{
Scope = Scope.Parse($"api.{partitionId}")
};
return Task.FromResult(customizedParams);
}
}
services.AddHttpClient("clientApi")
.ConfigureHttpClient(client => client.BaseAddress = new Uri("https://api.example.com"))
.AddClientCredentialsTokenHandler(
new ByPartitionIdTokenRequestCustomizer(),
ClientCredentialsClientName.Parse("example-client"));