HmacAuthorizationHeaderBuilder Class
Definition
- Namespace
- Cuemon.AspNetCore.Authentication.Hmac
- Assemblies
- Cuemon.AspNetCore.Authentication.dll
Provides a way to fluently represent a HTTP HMAC Authentication header.
public class HmacAuthorizationHeaderBuilder : HmacAuthorizationHeaderBuilder<HmacAuthorizationHeaderBuilder>
- Inheritance
-
HmacAuthorizationHeaderBuilder
- Inherited Members
Examples
The following example demonstrates how to build an HMAC authorization header for an outgoing HTTP request.
using System;
using System.Globalization;
using System.Net.Http;
using Cuemon.AspNetCore.Authentication.Hmac;
namespace MyApp.Examples;
public static class HmacAuthorizationHeaderBuilderExample
{
public static void Demonstrate()
{
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.cuemon.net/resource?name=Agent");
request.Headers.Date = DateTimeOffset.Parse("2022-07-10T12:50:42Z", CultureInfo.InvariantCulture);
request.Headers.Host = "api.cuemon.net";
var builder = new HmacAuthorizationHeaderBuilder()
.AddFromRequest(request)
.AddClientId("Agent-Api")
.AddClientSecret("Test")
.AddCredentialScope("20220710/us-east-1/docs/request");
var header = builder.Build();
Console.WriteLine(header.ToString());
}
}
Constructors
| Name | Description |
|---|---|
| HmacAuthorizationHeaderBuilder(string, KeyedCryptoAlgorithm, UnkeyedCryptoAlgorithm) | Initializes a new instance of the HmacAuthorizationHeaderBuilder class. |
Properties
| Name | Description |
|---|---|
| Algorithm | Gets the non-keyed algorithm of the HTTP HMAC Authentication. |
| HmacAlgorithm | Gets the keyed algorithm of the HTTP HMAC Authentication. |
Methods
| Name | Description |
|---|---|
| AddCredentialScope(string) | Adds the credential scope that defines the remote resource. |
| AddFromRequest(HttpRequest) | Adds the necessary fields that is part of an HTTP request. |
| AddFromRequest(HttpRequestMessage) | Adds the necessary fields that is part of an HTTP request. |
| Build() | Builds an instance of HmacAuthorizationHeader that implements AuthorizationHeader. |
| ComputeCanonicalRequest() | Converts the request to a standardized (canonical) format and computes a message digest. |
| ComputeSignature() | Computes the signature of this instance using a series of hash-based message authentication codes (HMACs). |