Skip to content

10.0.0

Latest

Choose a tag to compare

@khoanguyen102 khoanguyen102 released this 15 Jan 07:56
· 1 commit to master since this release
c58172d

Update library to support .NET 10

Breaking Changes

Updates Duende.AccessTokenManagement from v3 to v4 (3.2.0 to 4.1.0)
https://docs.duendesoftware.com/accesstokenmanagement/upgrading/atm-v3-to-v4/
https://github.com/DuendeSoftware/foss/releases/tag/atm-4.0.0

Migration Guide

HowTo update Samhammer.Authentication.Client to use Duende v4
https://docs.duendesoftware.com/accesstokenmanagement/workers/#tab-panel-231 <- migrate clients to use typed values
https://docs.duendesoftware.com/accesstokenmanagement/advanced/client-credentials/#token-caching <- migrate to hybrid cache

NOTES to HybridCache
If you have any IDistributedCache instance e.g. for redis it will automatically be used.
So be aware that accesstokens are saved on this remote cache! You may want to add encryption for the cache.
https://docs.duendesoftware.com/accesstokenmanagement/advanced/client-credentials/#encrypting-cache-entries

//V3
builder.Services.AddDistributedMemoryCache();
builder.Services.AddClientCredentialsTokenManagement();

builder.Services.AddClientCredentialsOptions<ApiAuthOptions>(ApiAuthOptions.DefaultClientName, (client, authOptions) =>
{
    client.TokenEndpoint = authOptions.AccessTokenUrl;
    client.ClientId = authOptions.ClientId;
    client.ClientSecret = authOptions.ClientSecret;
});

builder.Services
    .AddHttpClient(ApiAuthOptions.DefaultClientName)
    .AddClientCredentialsTokenHandler(ApiAuthOptions.DefaultClientName);
//V4
builder.Services.AddClientCredentialsTokenManagement(); //adds also HybridCache if not added yet

builder.Services.AddClientCredentialsOptions<ApiAuthOptions>(ApiAuthOptions.DefaultClientName, (client, authOptions) =>
{
    client.TokenEndpoint = new Uri(authOptions.AccessTokenUrl);
    client.ClientId = ClientId.Parse(authOptions.ClientId);
    client.ClientSecret = ClientSecret.Parse(authOptions.ClientSecret);
});

builder.Services
    .AddHttpClient(ApiAuthOptions.DefaultClientName)
    .AddClientCredentialsTokenHandler(ClientCredentialsClientName.Parse(ApiAuthOptions.DefaultClientName));