AccessTokenClient 6.0.0-rc22

This is a prerelease version of AccessTokenClient.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package AccessTokenClient --version 6.0.0-rc22
                    
NuGet\Install-Package AccessTokenClient -Version 6.0.0-rc22
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AccessTokenClient" Version="6.0.0-rc22" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AccessTokenClient" Version="6.0.0-rc22" />
                    
Directory.Packages.props
<PackageReference Include="AccessTokenClient" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AccessTokenClient --version 6.0.0-rc22
                    
#r "nuget: AccessTokenClient, 6.0.0-rc22"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AccessTokenClient@6.0.0-rc22
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AccessTokenClient&version=6.0.0-rc22&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=AccessTokenClient&version=6.0.0-rc22&prerelease
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed