Class HmacFields
- Namespace
- Cuemon.AspNetCore.Authentication.Hmac
- Assembly
- Cuemon.AspNetCore.Authentication.dll
A collection of constants for HmacAuthorizationHeaderBuilder and related.
public static class HmacFields
- Inheritance
-
HmacFields
Examples
The following example demonstrates how to reference the field constants of HmacFields when building an HMAC authorization header.
using System;
using System.Net.Http;
using Cuemon.AspNetCore.Authentication.Hmac;
namespace MyApp.Examples;
public static class HmacFieldsExample
{
public static void Demonstrate()
{
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.example.com/resource");
request.Headers.Date = DateTimeOffset.UtcNow;
request.Headers.Host = "api.example.com";
var builder = new HmacAuthorizationHeaderBuilder()
.AddFromRequest(request)
.AddClientId("my-client")
.AddClientSecret("my-secret")
.AddCredentialScope("20250101/us-east-1/service/aws4_request");
var header = builder.Build();
Console.WriteLine(HmacFields.Scheme);
Console.WriteLine(HmacFields.SignedHeaders);
Console.WriteLine(HmacFields.CanonicalRequest);
}
}
Fields
CanonicalRequest
The parts of the canonical request.
public const string CanonicalRequest = "canonicalRequest"
Field Value
ClientId
The public key of the signing process.
public const string ClientId = "clientId"
Field Value
ClientSecret
The private key of the signing process.
public const string ClientSecret = "clientSecret"
Field Value
CredentialScope
The credential scope that defines the remote resource.
public const string CredentialScope = "credentialScope"
Field Value
HttpHeaders
The canonical headers.
public const string HttpHeaders = "canonicalHeaders"
Field Value
HttpHeadersDelimiter
The delimiter used to separate the key-value pairs of HttpHeaders.
public const char HttpHeadersDelimiter = ':'
Field Value
HttpMethod
The HTTP request method.
public const string HttpMethod = "httpRequestMethod"
Field Value
Payload
The request payload.
public const string Payload = "requestPayload"
Field Value
Scheme
The default authentication scheme of the HmacAuthorizationHeader.
public const string Scheme = "HMAC"
Field Value
Remarks
https://www.wolfe.id.au/2012/10/20/what-is-hmac-authentication-and-why-is-it-useful/, https://docs.microsoft.com/en-us/azure/azure-app-configuration/rest-api-authentication-hmac and https://docs.cuemon.net/api/aspnet/Cuemon.AspNetCore.Authentication.Hmac.HmacAuthorizationHeader.html
ServerDateTime
The server date time expressed in ISO 8601 format.
public const string ServerDateTime = "serverDateTime"
Field Value
SignedHeaders
The headers that must be part of the signing process.
public const string SignedHeaders = "signedHeaders"
Field Value
SignedHeadersDelimiter
The delimiter used to separate the SignedHeaders.
public const char SignedHeadersDelimiter = ';'
Field Value
StringToSign
The parts of the string to sign.
public const string StringToSign = "stringToSign"
Field Value
UriPath
The canonical URI that is the URI-encoded version of the absolute path component of an URI.
public const string UriPath = "canonicalUri"
Field Value
UriQuery
The canonical query string.
public const string UriQuery = "canonicalQueryString"