Class JwtHttpHandler<T>
- Namespace
- Arc4u.OAuth2.Client.Authentication.Token
- Assembly
- Arc4u.OAuth2.Client.Authentication.dll
A DelegatingHandler that adds the token of the client user to the requests of an HttpClient. The token provider is selected by the ProviderId of the settings.
Nothing is added when the request already has an Authorization header or when no valid token is obtained. The culture of the user is added in the culture header.
public class JwtHttpHandler<T> : DelegatingHandler, IDisposable
Type Parameters
TThe type used as category of the logger.
- Inheritance
-
JwtHttpHandler<T>
- Implements
- Inherited Members
Constructors
JwtHttpHandler(IServiceProvider, ILogger<T>, IKeyValueSettings)
Initializes a new instance of the JwtHttpHandler<T> class from settings given directly. No inner handler is defined because this will be done via the AddHttpClient method in a service!
public JwtHttpHandler(IServiceProvider container, ILogger<T> logger, IKeyValueSettings settings)
Parameters
containerIServiceProviderThe scoped container
loggerILogger<T>The logger
settingsIKeyValueSettingsA key value collection.
Exceptions
- ArgumentNullException
An argument is null.
- ConfigurationException
No IApplicationContext is registered in the container.
JwtHttpHandler(IServiceProvider, ILogger<T>, string)
This is a ctor to use only in a frontend scenario. No inner handler is defined because this will be done via the AddHttpClient method in a service!
public JwtHttpHandler(IServiceProvider container, ILogger<T> logger, string resolvingName)
Parameters
containerIServiceProviderThe scoped container
loggerILogger<T>The logger
resolvingNamestringThe name of the SimpleKeyValueSettings options holding the settings.
Exceptions
- ConfigurationException
No settings exist with that name, or no IApplicationContext is registered in the container.
Methods
SendAsync(HttpRequestMessage, CancellationToken)
Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
requestHttpRequestMessageThe HTTP request message to send to the server.
cancellationTokenCancellationTokenA cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
The
requestwas null.- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.