I'm trying to get the list of blobs inside a folder using the Azure Rest API and I'm getting 403 Forbidden for a problem building the authorization signature for the Shared Key.
Here is my source code:
// Build the authorization signature
var requestDate = DateTime.UtcNow.ToString("R");
var canonicalizedResource = $"/{accountName}/{containerName} \ncomp:list\nprefix:contacts/{contactId}\nrestype:container";
var stringToSign = $"GET\n\n\n\n\n\n\n\n\n\n\n\n{requestDate}\nx-ms-version:2023-08-03\n{canonicalizedResource}";
string signature;
using (var hmac = new HMACSHA256(Convert.FromBase64String(accessKey)))
{
var dataToHmac = Encoding.UTF8.GetBytes(stringToSign);
signature = Convert.ToBase64String(hmac.ComputeHash(dataToHmac));
}
// Make the HTTP GET request
var url = $"https://{accountName}.blob.core.windows.net/{containerName}?restype=container&comp=list&prefix=contacts/{contactId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("x-ms-version", "2023-08-03");
client.DefaultRequestHeaders.Add("x-ms-date", requestDate);
client.DefaultRequestHeaders.Add("Authorization", $"SharedKey {accountName}:{signature}");
var response = await client.GetAsync(url);
// Process the response
if (response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine("List of blobs in the container:");
Console.WriteLine(responseContent);
}
else
{
Console.WriteLine($"Error getting list of blobs. Status code: {response.StatusCode}");
}
}
Am I missing something?

var stringToSign = $"GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:{requestDate}\nx-ms-version:2023-08-03\n{canonicalizedResource}";. I addedx-ms-date:to yourstringToSign.