AccessTokenClient 6.0.0-rc25
dotnet add package AccessTokenClient --version 6.0.0-rc25
NuGet\Install-Package AccessTokenClient -Version 6.0.0-rc25
<PackageReference Include="AccessTokenClient" Version="6.0.0-rc25" />
<PackageVersion Include="AccessTokenClient" Version="6.0.0-rc25" />
<PackageReference Include="AccessTokenClient" />
paket add AccessTokenClient --version 6.0.0-rc25
#r "nuget: AccessTokenClient, 6.0.0-rc25"
#:package AccessTokenClient@6.0.0-rc25
#addin nuget:?package=AccessTokenClient&version=6.0.0-rc25&prerelease
#tool nuget:?package=AccessTokenClient&version=6.0.0-rc25&prerelease
AccessTokenClient
A token client for making OAuth client credentials requests. Instead of re-writing the same access token client for every service, use this package to request tokens, cache them so they can be reused, and automatically attach them to outgoing HTTP requests.
Installation
dotnet add package AccessTokenClient
dotnet add package AccessTokenClient.Extensions
The AccessTokenClient.Extensions package contains the service collection extension methods used to register the token client:
services.AddAccessTokenClient();
Requesting an Access Token
Inject ITokenClient and call RequestAccessToken:
public class Service(ITokenClient client)
{
public async Task<string?> GetAccessToken()
{
var tokenResponse = await client.RequestAccessToken(new TokenRequest
{
TokenEndpoint = "https://www.token-endpoint.com/token",
ClientIdentifier = "client-identifier",
ClientSecret = "client-secret",
Scopes = ["scope:read"]
});
return tokenResponse.AccessToken;
}
}
The request uses the client credentials grant. If it succeeds, the returned TokenResponse contains the access token and its expiration in seconds.
Caching
Access tokens are not cached by default. To cache them in memory, register MemoryTokenResponseCache:
services.AddMemoryCache();
services.AddAccessTokenClient().AddAccessTokenClientCache<MemoryTokenResponseCache>();
To use a different store, such as a distributed cache, implement ITokenResponseCache and pass that type instead.
Automatically Adding the Access Token to Outgoing Requests
Implement ITokenRequestOptions, register it in the service collection, and add the access token handler to a client registered with AddHttpClient:
services.AddHttpClient<TestClient>().AddClientAccessTokenHandler<TestClientTokenOptions>();
The handler requests an access token and adds it to the authorization header of every request made by TestClient.
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
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Http (>= 10.0.15)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.15)
-
net11.0
- Microsoft.Extensions.Http (>= 11.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AccessTokenClient:
| Package | Downloads |
|---|---|
|
AccessTokenClient.Extensions
This package contains service collection extension methods to easily add the access token client to the service collection. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.0.0-rc25 | 58 | 11/18/2026 |
| 6.0.0-rc24 | 56 | 11/17/2026 |
| 6.0.0-rc23 | 57 | 11/17/2026 |
| 6.0.0-rc22 | 57 | 11/17/2026 |
| 6.0.0-rc21 | 57 | 11/17/2026 |
| 6.0.0-rc20 | 59 | 11/17/2026 |
| 6.0.0-rc19 | 57 | 11/17/2026 |
| 6.0.0-rc18 | 57 | 11/17/2026 |
| 6.0.0-rc17 | 63 | 11/17/2026 |
| 5.1.0 | 51,912 | 11/19/2025 |
| 5.0.0 | 95,099 | 3/3/2025 |
| 5.0.0-rc9 | 193 | 3/1/2025 |
| 5.0.0-rc14 | 144 | 1/23/2026 |
| 5.0.0-rc13 | 439 | 11/18/2025 |
| 5.0.0-rc12 | 431 | 11/17/2025 |
| 5.0.0-rc11 | 260 | 3/3/2025 |
| 5.0.0-rc10 | 275 | 3/3/2025 |
| 3.1.0 | 935 | 2/27/2025 |
| 3.1.0-rc7 | 163 | 2/27/2025 |
| 3.1.0-rc6 | 178 | 2/27/2025 |