Hello,
I am testing out using the Put Blob from URL operation to copy a photo from my Google Photos account to Azure Blobs. I am getting stuck at authorization of the request. I downloaded the storage-dotnet-rest-api-with-auth
repo to give me an example of how to interact with the API, and the provided List operation works fine. However, when I make my own request using the Put Blob from URL operation, I cannot authenticate. I believe I am providing all of the required headers, and it should be in correct canonicalized form because I am using the provided AzureStorageAuthenticationHelper.GetAuthorizationHeader()
method.
The request URL:
string containerName = "<containername>";
string blobName = "photo1.jpg";
String uri = string.Format("https://{0}.blob.core.windows.net/{1}/{2}", storageAccountName, containerName, blobName);
My header code:
DateTime now = DateTime.UtcNow;
httpRequestMessage.Headers.Add("x-ms-date", now.ToString("R", CultureInfo.InvariantCulture));
httpRequestMessage.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("image/jpeg");
httpRequestMessage.Headers.Add("x-ms-version", "2020-04-08");
httpRequestMessage.Headers.Add("x-ms-copy-source", "<url>");
httpRequestMessage.Headers.Add("x-ms-blob-type", "BlockBlob");
// If you need any additional headers, add them here before creating
// the authorization header.
// Add the authorization header.
httpRequestMessage.Headers.Authorization = AzureStorageAuthenticationHelper.GetAuthorizationHeader(
storageAccountName, storageAccountKey, now, httpRequestMessage);
The resulting request:
x-ms-date: Sun, 21 Feb 2021 16:00:49 GMT
x-ms-version: 2020-04-08
x-ms-copy-source: <url>
x-ms-blob-type: BlockBlob
Authorization: SharedKey <accountname>:<key>
Content-Type: image/jpeg
Content-Length: 0
https://myaccount.blob.core.windows.net/mycontainer/photo1.jpg
The response:
<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>AuthenticationFailed</Code>
<Message>
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:aea0e156-a01e-0037-3a6a-082086000000
Time:2021-02-21T16:00:48.6817608Z
</Message>
<AuthenticationErrorDetail>
The MAC signature found in the HTTP request '<signature>' is not the same as any computed signature. Server used following string to sign:
'PUT
image/jpeg
x-ms-blob-type:BlockBlob
x-ms-copy-source:<url>
x-ms-date:Sun, 21 Feb 2021 16:00:49 GMT
x-ms-version:2020-04-08
/myaccount/mycontainer/photo1.jpg'.
</AuthenticationErrorDetail>
</Error>
I have done a lot of searching and can't find a resolution to this problem. Most related issues are people strugging to get the canonicalized string correct but they aren't using the microsoft-provided method like I am which takes care of that.
What am I missing?
EDIT: If this is not the right place to post this question please redirect me.