I'm trying to use azure rest api from powershell but stuck with authorization part. Used to generate signature using this article https://msdn.microsoft.com/en-us/library/azure/dd179428.aspx
Script:
$StorageAccount = "account"
$Key = "key"
$sharedKey = [System.Convert]::FromBase64String($Key)
$date = [System.DateTime]::UtcNow.ToString("R")
$resource = "/test()?`$top" # also tried /test() /test /test()?`$top=1
$stringToSign = "$date`n/$StorageAccount$resource"
$hasher = New-Object System.Security.Cryptography.HMACSHA256
$hasher.Key = $sharedKey
$signedSignature = [System.Convert]::ToBase64String($hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($stringToSign)))
$authHeader = "SharedKeyLite ${StorageAccount}:$signedSignature"
$headers = @{"x-ms-date"=$date
"Authorization"=$authHeader
"Accept"="application/atom+xml"}
try {
$tables = Invoke-RestMethod -Uri "https://$StorageAccount.table.core.windows.net/test()?`$top=1" -Headers $headers |% {
$_.content.properties.tablename
}
} catch [Exception] {
$_
}
I was able to list tables (/tables) but when I try to execute some odata requests (/test()?$top=1 here) I am getting authorization error.