Aws4HmacFields Class
Definition
- Namespace
- Codebelt.Extensions.AwsSignature4
- Assemblies
- Codebelt.Extensions.AwsSignature4.dll
A collection of constants for Aws4HmacAuthorizationHeaderBuilder and related.
public static class Aws4HmacFields
- Inheritance
-
Aws4HmacFields
Examples
Examples
This example demonstrates using the Aws4HmacFields constants to construct AWS Signature Version 4 credential scope and authorization header components:
using System;
using Codebelt.Extensions.AwsSignature4;
namespace Aws4Example;
class Program
{
static void Main()
{
var timestamp = DateTime.UtcNow;
var region = "us-east-1";
var service = "s3";
var clientId = "AKIAIOSFODNN7EXAMPLE";
// Access Aws4HmacFields constants to build the credential scope
var dateStamp = timestamp.ToAwsDateString();
var credentialScope = $"{dateStamp}/{region}/{service}/{Aws4HmacFields.Aws4Request}";
// Format the Authorization header using Aws4HmacFields.Scheme
var signedHeaders = "host;x-amz-date;x-amz-content-sha256";
var signature = "computed-signature-hex-string";
var authorizationHeaderValue = $"{Aws4HmacFields.Scheme} Credential={clientId}/{credentialScope}, SignedHeaders={signedHeaders}, Signature={signature}";
// Retrieve other Aws4HmacFields constants for date formatting
var dateTimeStampFormat = Aws4HmacFields.DateTimeStampFormat;
var dateStampFormat = Aws4HmacFields.DateStampFormat;
var dateTimeStamp = timestamp.ToString(dateTimeStampFormat);
Console.WriteLine($"Scheme: {Aws4HmacFields.Scheme}");
Console.WriteLine($"Date-Time Stamp Format: {dateTimeStampFormat}");
Console.WriteLine($"Date-Time Stamp: {dateTimeStamp}");
Console.WriteLine($"Credential Scope: {credentialScope}");
Console.WriteLine($"Authorization Header: {authorizationHeaderValue}");
}
}
Fields
| Name | Description |
|---|---|
| Aws4Request | The final part of the signing key tied to a CredentialScope. |
| DateStamp | The date only value of the request expressed as, what Amazon calls, an ISO8601 basic date format. |
| DateStampFormat | The AWS date only format used when converting a DateTime value to its equivalent string representation. |
| DateTimeStamp | The date-time value of the request expressed as, what Amazon calls, an ISO8601 basic date time format. |
| DateTimeStampFormat | The AWS date-time format used when converting a DateTime value to its equivalent string representation. |
| Region | The region part of the signing key tied to a CredentialScope. |
| Scheme | The authentication scheme of the Aws4HmacAuthorizationHeader. |
| Service | The service part of the signing key tied to a CredentialScope. |