Class ClientCredentialsAccessTokenProvider
- Namespace
- Cratis.Arc.Connections
- Assembly
- Cratis.Arc.Core.dll
Represents an IConnectionResolverAccessTokenProvider for the OAuth 2.0 client credentials grant.
[IgnoreConvention]
public class ClientCredentialsAccessTokenProvider : IConnectionResolverAccessTokenProvider
- Inheritance
-
ClientCredentialsAccessTokenProvider
- Implements
- Inherited Members
- Extension Methods
Remarks
Posts grant_type=client_credentials with the client id, the client secret and the scope to the configured token endpoint,
and reads access_token and expires_in from the answer. A token without expires_in is used for one call only.
The secret and the token are never logged.
Constructors
ClientCredentialsAccessTokenProvider()
Initializes a new instance of the ClientCredentialsAccessTokenProvider class with the shared connection resolution HttpClient.
public ClientCredentialsAccessTokenProvider()
ClientCredentialsAccessTokenProvider(HttpClient, TimeProvider)
Represents an IConnectionResolverAccessTokenProvider for the OAuth 2.0 client credentials grant.
public ClientCredentialsAccessTokenProvider(HttpClient httpClient, TimeProvider timeProvider)
Parameters
httpClientHttpClientThe HttpClient to call the token endpoint with.
timeProviderTimeProviderThe TimeProvider expiry is computed from.
Remarks
Posts grant_type=client_credentials with the client id, the client secret and the scope to the configured token endpoint,
and reads access_token and expires_in from the answer. A token without expires_in is used for one call only.
The secret and the token are never logged.
Methods
CanProvide(HttpConnectionResolverAuthenticationOptions)
Check whether the provider can provide tokens for the given options.
public bool CanProvide(HttpConnectionResolverAuthenticationOptions options)
Parameters
Returns
- bool
True if it can, false if not.
GetToken(HttpConnectionResolverAuthenticationOptions, CancellationToken)
Get a fresh token.
public ValueTask<ConnectionResolverAccessToken> GetToken(HttpConnectionResolverAuthenticationOptions options, CancellationToken cancellationToken)
Parameters
optionsHttpConnectionResolverAuthenticationOptionscancellationTokenCancellationTokenThe CancellationToken.
Returns
Exceptions
- ConnectionResolverTokenEndpointMustUseHttps
The token endpoint does not use HTTPS or HTTP on a loopback host.