Table of Contents

Class ClientCredentialsTokenProvider

Namespace
Arc4u.OAuth2.TokenProvider
Assembly
Arc4u.OAuth2.AspNetCore.dll

grant_type=client_credentials token provider authenticating the client with the client_secret_basic method: the ClientId/ClientSecret pair is sent in the HTTP Authorization: Basic base64(client_id:client_secret) header, while the scope and any extra parameter (e.g. resource) travel in the form body.

It consumes the settings produced by ClientCredentialsScenario and caches the acquired application token by client + scope + authority, refreshing it close to expiry.

[Export("ClientCredentials", typeof(ITokenProvider))]
[Shared]
public class ClientCredentialsTokenProvider : ITokenProvider
Inheritance
ClientCredentialsTokenProvider
Implements
Inherited Members

Constructors

ClientCredentialsTokenProvider(IHttpClientFactory, ITokenCache, IOptionsMonitor<AuthorityOptions>, ILogger<ClientCredentialsTokenProvider>)

grant_type=client_credentials token provider authenticating the client with the client_secret_basic method: the ClientId/ClientSecret pair is sent in the HTTP Authorization: Basic base64(client_id:client_secret) header, while the scope and any extra parameter (e.g. resource) travel in the form body.

It consumes the settings produced by ClientCredentialsScenario and caches the acquired application token by client + scope + authority, refreshing it close to expiry.

public ClientCredentialsTokenProvider(IHttpClientFactory httpClientFactory, ITokenCache tokenCache, IOptionsMonitor<AuthorityOptions> authorities, ILogger<ClientCredentialsTokenProvider> logger)

Parameters

httpClientFactory IHttpClientFactory
tokenCache ITokenCache
authorities IOptionsMonitor<AuthorityOptions>
logger ILogger<ClientCredentialsTokenProvider>

Fields

ProviderName

The key (ClientCredentials) under which the provider is registered.

public const string ProviderName = "ClientCredentials"

Field Value

string

Methods

GetTokenAsync(IKeyValueSettings?, object?)

Gets an application token with the client credentials grant. The ClientId, ClientSecret and Scope settings are required; the authority is taken from the Authority setting (or the Default authority). A cached token is returned until it expires in less than one minute.

public ValueTask<Result<TokenInfo>> GetTokenAsync(IKeyValueSettings? settings, object? _)

Parameters

settings IKeyValueSettings

The provider settings (see TokenKeys).

_ object

Not used.

Returns

ValueTask<Result<TokenInfo>>

The token, or a failed result when a required setting is missing or the token cannot be obtained.

Exceptions

ArgumentNullException

settings is null.