Class JwtHttpHandler<T>
A DelegatingHandler that adds the token of the current 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,
when the authentication type of the settings differs from the one of the current identity (unless it is Inject), when no provider or no valid token is found.
The culture of the user is added in a 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. To use in a backend scenario, where no platform parameters are used. No inner handler is defined because this will be done via the AddHttpClient method in a service!
public JwtHttpHandler(IServiceProvider serviceProvider, ILogger<T> logger, IKeyValueSettings keyValuesSettings)
Parameters
serviceProviderIServiceProviderThe service provider, used when no scoped service provider is available (for example outside of a request).
loggerILogger<T>The logger.
keyValuesSettingsIKeyValueSettingsThe settings selecting the token provider (
ProviderId) and the authentication type.
Exceptions
- ArgumentNullException
keyValuesSettingsis null.
JwtHttpHandler(IServiceProvider, ILogger<T>, string)
Initializes a new instance of the JwtHttpHandler<T> class with the settings registered by name. To use in a backend scenario, where no platform parameters are used. No inner handler is defined because this will be done via the AddHttpClient method in a service!
public JwtHttpHandler(IServiceProvider serviceProvider, ILogger<T> logger, string resolvingName)
Parameters
serviceProviderIServiceProviderThe service provider, used to resolve the settings and when no scoped service provider is available (for example outside of a request).
loggerILogger<T>The logger.
resolvingNamestringThe name of the SimpleKeyValueSettings options selecting the token provider (
ProviderId) and the authentication type.
Exceptions
- ConfigurationException
No settings exist with that name.
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.