I am unable to query storage tables using this documentation.
Here is the function I am using to get a shared key in order to authenticate against the Azure storage table.
function Get-SharedKeyLiteAuthHeader {
param(
[Parameter(Mandatory = $TRUE)]
[String]
$StorageAccount,
[Parameter(Mandatory = $TRUE)]
[String]
$TableName,
[Parameter(Mandatory = $TRUE)]
[String]
$AccessKey,
[Parameter(Mandatory = $FALSE)]
[String]
$Version = "2020-04-08"
)
$GMTTime = (Get-Date).ToUniversalTime().toString('R')
$StringToSign = "$GMTTime`n/$($StorageAccount)/$($TableName)"
$Hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$Hmacsha.key = [Convert]::FromBase64String($AccessKey)
$Signature = $Hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($StringToSign))
$Signature = [Convert]::ToBase64String($Signature)
return @{
'x-ms-date' = $GMTTime
Authorization = "SharedKeyLite " + $StorageAccount + ":" + $Signature
"x-ms-version" = $Version
Accept = "application/json;odata=fullmetadata"
}
}
Here is the REST call I am making that returns all table entries & returns a status code of 200.
$Uri = "https://$($StorageAccount).table.core.windows.net/$($TableName)"
$Headers = Get-SharedKeyLiteAuthHeader -StorageAccount $StorageAccount -TableName $TableName -AccessKey $AccessKey
$AllEntries = Invoke-RestMethod -Method GET -Uri $Uri -Headers $Headers -ContentType application/json
Here is the REST call I am making that returns 403 AuthenticationFailed.
$Uri = "https://$($StorageAccount).table.core.windows.net/$($TableName)()?$top=2"
$Headers = Get-SharedKeyLiteAuthHeader -StorageAccount $StorageAccount -TableName $TableName -AccessKey $AccessKey
$SomeEntries = Invoke-RestMethod -Method GET -Uri $Uri -Headers $Headers -ContentType application/json
My end goal is to filter by date, but I can't get any of the query parameters working. I suspect it has to do with missing header elements, but I can't pin down what those might be as this documentation that discusses the header elements required lists all of the elements that I have already specified.
Any help is appreciated - thank you.
question from:
https://stackoverflow.com/questions/66055624/running-a-query-against-an-azure-storage-table-returns-403-authenticationfailed 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…