Table of Contents

Class JwtHttpHandler<T>

Namespace
Arc4u.OAuth2.Token
Assembly
Arc4u.OAuth2.AspNetCore.Authentication.dll

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

T

The 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

serviceProvider IServiceProvider

The service provider, used when no scoped service provider is available (for example outside of a request).

logger ILogger<T>

The logger.

keyValuesSettings IKeyValueSettings

The settings selecting the token provider (ProviderId) and the authentication type.

Exceptions

ArgumentNullException

keyValuesSettings is 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

serviceProvider IServiceProvider

The service provider, used to resolve the settings and when no scoped service provider is available (for example outside of a request).

logger ILogger<T>

The logger.

resolvingName string

The 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

request HttpRequestMessage

The HTTP request message to send to the server.

cancellationToken CancellationToken

A cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

The request was null.

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.