0
我想从powershell中使用azure休息API,但坚持授权部分。用于使用本文https://msdn.microsoft.com/en-us/library/azure/dd179428.aspxAzure表休息api授权
脚本生成签名:
$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] {
$_
}
我能列出表(/表),但是当我试图执行一些OData的请求(/测试()$ top = 1 here)我收到授权错误。
感谢您的回复! '$ Key'是我的存储帐户中的主键。当我将$ resource设置为'/ test()'请求失败并出现auth错误时'服务器无法验证请求。确保授权标头的值正确形成,包括签名.' – forik
我还使用'$ key'创建了新表,但我继续收到授权错误:( – forik
)您的脚本是正确的。尝试使用Azure存储资源管理器存储帐户和密钥如果不工作,请重新生成密钥。 –