Esempio n. 1
0
 public RequestsSignatureDelegatingHandler(
     RequestsSignatureOptions options,
     ISignatureBodySourceBuilder signatureBodySourceBuilder = null,
     ISignatureBodySigner signatureBodySigner = null)
 {
     _options = options ?? throw new ArgumentNullException(nameof(options));
     _signatureBodySourceBuilder = signatureBodySourceBuilder ?? new SignatureBodySourceBuilder();
     _signatureBodySigner        = signatureBodySigner ?? new HashAlgorithmSignatureBodySigner();
 }
 /// <summary>
 /// Adds <see cref="RequestsSignatureDelegatingHandler"/> as a HttpMessageHandler in the client pipeline.
 /// </summary>
 /// <param name="httpClientBuilder">The <see cref="IHttpClientBuilder"/>.</param>
 /// <param name="options">The <see cref="RequestsSignatureOptions"/> to use. If not provided will retrieve from the container.</param>
 /// <param name="signatureBodySourceBuilder">The <see cref="ISignatureBodySourceBuilder"/>. If not provided will try to retrieve from the container.</param>
 /// <param name="signatureBodySigner">The <see cref="ISignatureBodySigner"/>. If not provided will try to retrieve from the container.</param>
 /// <returns>The updated <see cref="IHttpClientBuilder"/>.</returns>
 public static IHttpClientBuilder AddRequestsSignature(
     this IHttpClientBuilder httpClientBuilder,
     RequestsSignatureOptions options = null,
     ISignatureBodySourceBuilder signatureBodySourceBuilder = null,
     ISignatureBodySigner signatureBodySigner = null)
 => httpClientBuilder.AddHttpMessageHandler(
     (sp) => new RequestsSignatureDelegatingHandler(
         options ?? sp.GetRequiredService <RequestsSignatureOptions>(),
         signatureBodySourceBuilder: signatureBodySourceBuilder ?? sp.GetService <ISignatureBodySourceBuilder>(),
         signatureBodySigner: signatureBodySigner ?? sp.GetService <ISignatureBodySigner>()));
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RequestsSignatureValidationService"/> class.
 /// </summary>
 /// <param name="options">The <see cref="RequestsSignatureOptions"/>.</param>
 /// <param name="signatureBodySourceBuilder">The <see cref="ISignatureBodySourceBuilder"/>.</param>
 /// <param name="signatureBodySigner">The <see cref="ISignatureBodySigner"/>.</param>
 /// <param name="clock">The <see cref="ISystemClock"/> instance for time retrieval. Defaults to <see cref="SystemClock"/>.</param>
 /// <param name="nonceRepository">The <see cref="INonceRepository"/> to use. Defaults to <see cref="NullNonceRepository"/>.</param>
 /// <param name="logger">The <see cref="ILogger"/> to use. Defaults to <see cref="NullLogger"/>.</param>
 public RequestsSignatureValidationService(
     IOptionsMonitor <RequestsSignatureOptions> options,
     ISignatureBodySourceBuilder signatureBodySourceBuilder,
     ISignatureBodySigner signatureBodySigner,
     ISystemClock clock = null,
     INonceRepository nonceRepository = null,
     ILogger <RequestsSignatureValidationService> logger = null)
 {
     _optionsMonitor             = options ?? throw new ArgumentNullException(nameof(options));
     _signatureBodySourceBuilder = signatureBodySourceBuilder ?? throw new ArgumentNullException(nameof(signatureBodySourceBuilder));
     _signatureBodySigner        = signatureBodySigner ?? throw new ArgumentNullException(nameof(signatureBodySigner));
     _clock           = clock ?? new SystemClock();
     _nonceRepository = nonceRepository ?? NullNonceRepository.Instance;
     _logger          = (ILogger)logger ?? NullLogger.Instance;
     _optionsMonitor.OnChange(OnOptionsChange);
     OnOptionsChange(_optionsMonitor.CurrentValue);
 }