Class JwtHttpHandler
A DelegatingHandler that adds the token of the current user to the requests of an HttpClient of a Blazor application.
The token is requested from the ITokenProvider designated by the ProviderId key of the settings and sent in the Authorization header. Errors are logged and the request is sent without token.
public class JwtHttpHandler : DelegatingHandler, IDisposable
- Inheritance
-
JwtHttpHandler
- Implements
- Inherited Members
Constructors
JwtHttpHandler(IServiceProvider, ILogger<JwtHttpHandler>, IKeyValueSettings)
A DelegatingHandler that adds the token of the current user to the requests of an HttpClient of a Blazor application.
The token is requested from the ITokenProvider designated by the ProviderId key of the settings and sent in the Authorization header. Errors are logged and the request is sent without token.
public JwtHttpHandler(IServiceProvider container, ILogger<JwtHttpHandler> logger, IKeyValueSettings settings)
Parameters
containerIServiceProviderThe service provider used to resolve the keyed token provider.
loggerILogger<JwtHttpHandler>The logger.
settingsIKeyValueSettingsThe settings designating the token provider.
JwtHttpHandler(IServiceProvider, ILogger<JwtHttpHandler>, string)
Initializes a new instance of the JwtHttpHandler class with the settings registered by name.
public JwtHttpHandler(IServiceProvider container, ILogger<JwtHttpHandler> logger, string resolvingName)
Parameters
containerIServiceProviderThe service provider used to resolve the settings and the keyed token provider.
loggerILogger<JwtHttpHandler>The logger.
resolvingNamestringThe name of the SimpleKeyValueSettings options designating the token provider.
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.