I am attempting to write a PowerShell script for uploading files to an Azure File Share (SMB) and due to ISP issue's I'm required to use the REST API instead of the SMB protocol. I have working code for creating folders, directories, and empty files. However when I attempt to use the Put Range service (https://learn.microsoft.com/en-us/rest/api/storageservices/put-range) I run into issues with the server rejecting my signed authorization.
The auth string I'm signing looks like this:
$stringToSign = "PUTn
nn3488
nn
nn
nn
nn
nx-ms-date:$datenx-ms-range:bytes=0-3487
nx-ms-version:$versionnx-ms-write:update
n/$storageAccount/$resource?comp=range"
The response from the server is this:
Invoke-RestMethod : AuthenticationFailedServer failed to authenticate the request. Make sure the value of
Authorization header is formed correctly including the signature.
RequestId:f995523a-701a-0047-71d1-1f93bb000000
Time:2023-01-04T00:16:22.9268980ZThe MAC signature found in the HTTP request
'pwRgIfKnp0ss/XP77syYEHm40vmLx6oxrYSh59ER55k=' is not the same as any computed signature. Server used following
string to sign: 'PUT
x-ms-date:Wed, 04 Jan 2023 00:16:16 GMT
x-ms-range:bytes=0-3487
x-ms-version:2017-04-17
x-ms-write:update
/storageaccount/share/folder/filename.csv
comp:range'.
And the headers sent with the request are:
x-ms-date: Wed, 04 Jan 2023 00:16:16 GMT
x-ms-range: bytes=0-3487
x-ms-version: 2017-04-17
Content-Length: 3488
Authorization: SharedKey storageaccount:pwRgIfKnp0ss/XP77syYEHm40vmLx6oxrYSh59ER55k=
x-ms-write: update
I've noticed that the Content-Length header (even though provided to sign) doesn't show up in the server's response. I also tried using '0' in the Content-Length signing string location and used the x-ms-content-length header instead, which results in the same error returned from the server.
Is there anyone who might be able to offer insight into where I might be going wrong?