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
httpClientFactoryIHttpClientFactorytokenCacheITokenCacheauthoritiesIOptionsMonitor<AuthorityOptions>loggerILogger<ClientCredentialsTokenProvider>
Fields
ProviderName
The key (ClientCredentials) under which the provider is registered.
public const string ProviderName = "ClientCredentials"
Field Value
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
settingsIKeyValueSettingsThe provider settings (see TokenKeys).
_objectNot 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
settingsis null.