Class HttpConnectionResolver
- Namespace
- Cratis.Arc.Connections
- Assembly
- Cratis.Arc.Core.dll
Represents an IConnectionResolver that resolves by calling an HTTP endpoint.
[IgnoreConvention]
public class HttpConnectionResolver : IConnectionResolver
- Inheritance
-
HttpConnectionResolver
- Implements
- Inherited Members
- Extension Methods
Remarks
The request is posted as JSON — { "storage": "SqlServer", "purpose": "Runtime", "scope": { "tenant": "acme" } } —
and the endpoint answers with a ResolvedConnection as JSON, where every property is optional. An endpoint
answering 204 No Content leaves the configured connection as it is. Any other unsuccessful status fails.
With Authentication configured, every request carries Authorization: Bearer
with a cached token. When the endpoint answers 401 Unauthorized, the token is dropped and the request is sent once more
with a fresh one.
The answer typically carries credentials. It is never logged or persisted, and neither are bearer tokens.
Constructors
HttpConnectionResolver(HttpConnectionResolverOptions, HttpClient)
Initializes a new instance of the HttpConnectionResolver class.
public HttpConnectionResolver(HttpConnectionResolverOptions options, HttpClient httpClient)
Parameters
optionsHttpConnectionResolverOptionshttpClientHttpClientThe HttpClient to call the endpoint with.
Remarks
Supports ClientCredentials authentication, with tokens requested through httpClient.
Exceptions
- HttpConnectionResolverEndpointNotConfigured
No endpoint is configured.
- HttpConnectionResolverAuthorizationHeaderConflict
Both an
Authorizationheader and authentication are configured.- HttpConnectionResolverAuthenticationNotSupported
No provider can provide tokens for the configured authentication.
HttpConnectionResolver(HttpConnectionResolverOptions, HttpClient, IEnumerable<IConnectionResolverAccessTokenProvider>, TimeProvider)
Represents an IConnectionResolver that resolves by calling an HTTP endpoint.
public HttpConnectionResolver(HttpConnectionResolverOptions options, HttpClient httpClient, IEnumerable<IConnectionResolverAccessTokenProvider> accessTokenProviders, TimeProvider timeProvider)
Parameters
optionsHttpConnectionResolverOptionshttpClientHttpClientThe HttpClient to call the endpoint with.
accessTokenProvidersIEnumerable<IConnectionResolverAccessTokenProvider>The IConnectionResolverAccessTokenProvider instances to choose from when authentication is configured. The first that can provide is used.
timeProviderTimeProviderThe TimeProvider token expiry is checked against.
Remarks
The request is posted as JSON — { "storage": "SqlServer", "purpose": "Runtime", "scope": { "tenant": "acme" } } —
and the endpoint answers with a ResolvedConnection as JSON, where every property is optional. An endpoint
answering 204 No Content leaves the configured connection as it is. Any other unsuccessful status fails.
With Authentication configured, every request carries Authorization: Bearer
with a cached token. When the endpoint answers 401 Unauthorized, the token is dropped and the request is sent once more
with a fresh one.
The answer typically carries credentials. It is never logged or persisted, and neither are bearer tokens.
Exceptions
- HttpConnectionResolverEndpointNotConfigured
No endpoint is configured.
- HttpConnectionResolverAuthorizationHeaderConflict
Both an
Authorizationheader and authentication are configured.- HttpConnectionResolverAuthenticationNotSupported
No provider can provide tokens for the configured authentication.
Methods
Resolve(ConnectionRequest, CancellationToken)
Resolve a connection.
public Task<ResolvedConnection> Resolve(ConnectionRequest request, CancellationToken cancellationToken = default)
Parameters
requestConnectionRequestThe ConnectionRequest to resolve for.
cancellationTokenCancellationTokenOptional CancellationToken.
Returns
- Task<ResolvedConnection>
The ResolvedConnection. Use Unchanged to keep the configured connection.
Exceptions
- HttpConnectionResolverEndpointNotConfigured
No endpoint is configured.
- HttpConnectionResolverAuthorizationHeaderConflict
Both an
Authorizationheader and authentication are configured.- HttpConnectionResolverAuthenticationNotSupported
No provider can provide tokens for the configured authentication.