AccessTokenClient 6.0.0-rc18

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-rc18
                    
NuGet\Install-Package AccessTokenClient -Version 6.0.0-rc18
                    
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-rc18" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AccessTokenClient" Version="6.0.0-rc18" />
                    
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-rc18
                    
#r "nuget: AccessTokenClient, 6.0.0-rc18"
                    
#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-rc18
                    
#: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-rc18&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=AccessTokenClient&version=6.0.0-rc18&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 66 11/18/2026
6.0.0-rc24 64 11/17/2026
6.0.0-rc23 66 11/17/2026
6.0.0-rc22 66 11/17/2026
6.0.0-rc21 66 11/17/2026
6.0.0-rc20 67 11/17/2026
6.0.0-rc19 66 11/17/2026
6.0.0-rc18 66 11/17/2026
6.0.0-rc17 70 11/17/2026
5.1.0 52,202 11/19/2025
5.0.0 95,166 3/3/2025
5.0.0-rc9 194 3/1/2025
5.0.0-rc14 145 1/23/2026
5.0.0-rc13 440 11/18/2025
5.0.0-rc12 432 11/17/2025
5.0.0-rc11 261 3/3/2025
5.0.0-rc10 276 3/3/2025
3.1.0 985 2/27/2025
3.1.0-rc7 164 2/27/2025
3.1.0-rc6 179 2/27/2025
Loading failed