Aws4HmacAuthorizationHeaderBuilder Class
Definition
- Namespace
- Codebelt.Extensions.AwsSignature4
- Assemblies
- Codebelt.Extensions.AwsSignature4.dll
Provides a way to fluently represent a HTTP AWS4-HMAC-SHA256 Authentication header.
public class Aws4HmacAuthorizationHeaderBuilder : HmacAuthorizationHeaderBuilder<Aws4HmacAuthorizationHeaderBuilder>
- Inheritance
-
Aws4HmacAuthorizationHeaderBuilder
- Inherited Members
Examples
Examples
This example demonstrates how to build an AWS Signature Version 4 authorization header using the fluent builder API:
using System;
using Codebelt.Extensions.AwsSignature4;
namespace Aws4Example;
class Program
{
static void Main()
{
var timestamp = DateTime.UtcNow;
// Create the builder and add credentials
var headerBuilder = new Aws4HmacAuthorizationHeaderBuilder()
.AddClientId("AKIAIOSFODNN7EXAMPLE")
.AddClientSecret("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
.AddCredentialScope(timestamp);
Console.WriteLine($"Client ID: AKIAIOSFODNN7EXAMPLE");
Console.WriteLine($"Credential Scope: {timestamp.ToAwsDateString()}/eu-west-1/s3/aws4_request");
Console.WriteLine("");
Console.WriteLine("To complete the header:");
Console.WriteLine("1. Call AddFromRequest() with an HttpRequest to populate headers, method, URI, and payload");
Console.WriteLine("2. Call Build() to generate the AWS4-HMAC-SHA256 Authorization header");
}
}
For a complete, real-world example that demonstrates building a full AWS Signature Version 4 header from an HttpRequest, see the Aws4HmacAuthorizationHeaderBuilderTest unit test in the repository.
Remarks
Constructors
| Name | Description |
|---|---|
| Aws4HmacAuthorizationHeaderBuilder() | Initializes a new instance of the Aws4HmacAuthorizationHeaderBuilder class. |
Methods
| Name | Description |
|---|---|
| AddCredentialScope(DateTime, string, string, string) | Adds the credential scope that defines the remote resource. |
| AddFromRequest(HttpRequest) | 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). |