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
domainstringThe Auth0 domain (e.g., "your-tenant.auth0.com").
clientIdstringThe client ID of the application.
clientSecretstringThe client secret of the application.
audiencestringThe API audience. Defaults to
https://{domain}/api/v2/.httpClientHttpClientAn 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
cancellationTokenCancellationTokenA token to cancel the operation.