Skip to content

Latest commit

 

History

History
34 lines (28 loc) · 1.27 KB

GiG.Core.Http.Authentication.Hmac.md

File metadata and controls

34 lines (28 loc) · 1.27 KB

GiG.Core.Http.Authentication.Hmac

This Library provides an API to register an HmacDelegatingHandler onto the HttpClient. When using this Library, the library will inject the Hmac header to the request.

Basic Usage

Make use of the HmacDelegatingHandler() when configuring your HttpClientFactory. The Handler depends on GiG.Core.Http.Security.Hmac.IHmacOptionsProvider,GiG.Core.Security.Cryptography.IHashProviderFactory,GiG.Core.Security.Http.IHmacSignatureProvider.

var client = HttpClientFactory.CreateClient(x => 
{
	x.AddHttpMessageHandler(new HmacDelegatingHandler(
		new DefaultHmacOptionsProvider(options),
		new HashProviderFactory(hashFuncFactory),
		new HmacSignatureProvider()));
});

Make use of AddHmacDelegatingHandler when configuring your HttpClient. Note: The FromConfiguration extension can be found in the nuget package GiG.Core.Http.Extensions

public static void ConfigureServices(HostBuilderContext ctx, IServiceCollection services)
{
    services
        .AddHttpClient("Payments", 
            client => 
            {
                client.FromConfiguration(ctx.Configuration, "Payments"); 
            })
        .AddHmacDelegatingHandler()
		.ConfigureDefaultHmacDelegatingHandlerOptionProvider(_configuration);
}