Table of Contents

Class ClientCredentialsTokenProvider

Namespace
Auth0.ManagementApi
Assembly
Auth0.ManagementApi.dll

An ITokenProvider that automatically acquires and caches tokens via the OAuth 2.0 client credentials grant.

Tokens are cached until they expire (with a 10-second leeway for safety) and refreshed transparently on the next call.

public sealed class ClientCredentialsTokenProvider : ITokenProvider, IDisposable
Inheritance
ClientCredentialsTokenProvider
Implements
Inherited Members
Extension Methods

Constructors

ClientCredentialsTokenProvider(string, string, string, string?, HttpClient?)

Creates a new ClientCredentialsTokenProvider for automatic token acquisition.

public ClientCredentialsTokenProvider(string domain, string clientId, string clientSecret, string? audience = null, HttpClient? httpClient = null)

Parameters

domain string

The Auth0 domain (e.g., "your-tenant.auth0.com").

clientId string

The client ID of the application.

clientSecret string

The client secret of the application.

audience string

The API audience. Defaults to https://{domain}/api/v2/.

httpClient HttpClient

An optional HttpClient for making token requests. If not provided, a new instance will be created and managed internally.

Methods

Dispose()

Releases resources held by this provider.

public void Dispose()

GetTokenAsync(CancellationToken)

Returns a valid access token, fetching a new one from Auth0 if the cached token has expired or does not yet exist. Thread-safe.

public Task<string> GetTokenAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<string>