AccessTokenClient.Extensions
6.0.0-rc25
dotnet add package AccessTokenClient.Extensions --version 6.0.0-rc25
NuGet\Install-Package AccessTokenClient.Extensions -Version 6.0.0-rc25
<PackageReference Include="AccessTokenClient.Extensions" Version="6.0.0-rc25" />
<PackageVersion Include="AccessTokenClient.Extensions" Version="6.0.0-rc25" />
<PackageReference Include="AccessTokenClient.Extensions" />
paket add AccessTokenClient.Extensions --version 6.0.0-rc25
#r "nuget: AccessTokenClient.Extensions, 6.0.0-rc25"
#:package AccessTokenClient.Extensions@6.0.0-rc25
#addin nuget:?package=AccessTokenClient.Extensions&version=6.0.0-rc25&prerelease
#tool nuget:?package=AccessTokenClient.Extensions&version=6.0.0-rc25&prerelease
AccessTokenClient.Extensions
Service collection extension methods for registering the AccessTokenClient token client, along with a default retry policy for token requests.
Installation
dotnet add package AccessTokenClient.Extensions
Registering the Token Client
services.AddAccessTokenClient();
This registers ITokenClient, which can then be injected into controllers and services to make client credentials token requests.
Retrying Failed Token Requests
AddAccessTokenClient accepts an action that configures the IHttpClientBuilder used to register the token client. Use it to add a retry policy for requests to the token endpoint. A default policy is included:
services.AddAccessTokenClient(builder =>
{
builder.AddPolicyHandler((provider, _) =>
{
var logger = provider.GetService<ILogger<ITokenClient>>();
return AccessTokenClientPolicy.GetDefaultRetryPolicy(logger);
});
});
The default policy retries twice, waiting one second between attempts, when a transient error (5XX or 408) or a 404 is encountered. Retries are not enabled unless a policy is added.
Caching
Access tokens are not cached by default. Use AddAccessTokenClientCache to enable caching:
services.AddMemoryCache();
services.AddAccessTokenClient().AddAccessTokenClientCache<MemoryTokenResponseCache>(options =>
{
options.ExpirationBuffer = 5;
options.CacheKeyPrefix = "AccessTokenClient";
});
ExpirationBuffer is the number of minutes subtracted from the token's lifetime when it is cached, so a token is never cached longer than it is valid. A token with a lifetime that is not longer than the buffer is returned but not cached. CacheKeyPrefix is the prefix used for generated cache keys. The values shown are the defaults.
AddAccessTokenClientCache must be called after AddAccessTokenClient; an InvalidOperationException is thrown otherwise.
The type argument must implement ITokenResponseCache, so a custom cache such as a distributed cache can be used in place of MemoryTokenResponseCache.
Documentation
Full documentation is available in the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- AccessTokenClient (>= 6.0.0-rc25)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Http (>= 10.0.15)
- Microsoft.Extensions.Http.Polly (>= 10.0.15)
-
net11.0
- AccessTokenClient (>= 6.0.0-rc25)
- Microsoft.Extensions.Http (>= 11.0.0)
- Microsoft.Extensions.Http.Polly (>= 11.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.0.0-rc25 | 82 | 11/18/2026 |
| 6.0.0-rc24 | 73 | 11/17/2026 |
| 6.0.0-rc23 | 73 | 11/17/2026 |
| 6.0.0-rc22 | 71 | 11/17/2026 |
| 6.0.0-rc21 | 78 | 11/17/2026 |
| 6.0.0-rc20 | 75 | 11/17/2026 |
| 6.0.0-rc19 | 78 | 11/17/2026 |
| 6.0.0-rc18 | 77 | 11/17/2026 |
| 6.0.0-rc17 | 79 | 11/17/2026 |
| 5.1.0 | 49,908 | 11/19/2025 |
| 5.0.0 | 81,687 | 3/3/2025 |
| 5.0.0-rc9 | 219 | 3/1/2025 |
| 5.0.0-rc14 | 159 | 1/23/2026 |
| 5.0.0-rc13 | 456 | 11/18/2025 |
| 5.0.0-rc12 | 444 | 11/17/2025 |
| 5.0.0-rc11 | 280 | 3/3/2025 |
| 5.0.0-rc10 | 292 | 3/3/2025 |
| 3.1.0 | 952 | 2/27/2025 |
| 3.1.0-rc7 | 196 | 2/27/2025 |
| 3.1.0-rc6 | 210 | 2/27/2025 |