无法使用 Microsoft 示例在 Azure APIM 中生成 SAS

问题描述 投票:0回答:3

有人按照下面的示例成功为 Azure APIM 中的 Blob 存储生成 SAS 吗?

https://learn.microsoft.com/en-us/azure/api-management/policies/generate-shared-access-signature

已替换门户中的存储访问密钥(使用 key1 和 key 2),但得到相同的结果。也尝试生成新密钥,但也不起作用。

“表达式评估失败。给定的键不存在于 字典。 在 System.Collections.Generic.Dictionary`2.get_Item(TKey key)", “字典中不存在给定的键。”

让像我这样的 azure-apim 初学者更加困惑的是

<set-variable name="resourcePath" value="TableName()" />
,TableName() 是做什么的?

azure azure-api-management azure-sas
3个回答
2
投票

感谢所有试图提供帮助的人:安东和多丽丝。

失败的操作是这个块:

<set-variable name="StringToSign" value="@{
            return string.Format(
            "GET\n\n\n\n\n{0}\n\n\n\n\n\n\n{1}\n{2}\n{3}",
            (string)context.Variables["Content-Type"],
            (string)context.Variables["x-ms-date"],
            (string)context.Variables["x-ms-version"],
            (string)context.Variables["CanonicalizedResource"]);
        }" />

但是,在示例的开头,当设置上下文变量时,x-ms-version 丢失了。我添加了操作

<set-variable name="x-ms-version" value="2020-02-10" />
,现在正在生成 SAS。

也许它会帮助其他想要使用azure的人:)


0
投票

此示例为 Azure 存储帐户中的表生成 SAS 令牌。您可以将其修改为您想要访问的资源,如下所示:

<set-variable name="resourcePath" value="containername/blobname" />

也不要忘记更改

rewrite-uri
块。


0
投票

我还尝试使用 Azure APIM 策略生成 SAS 令牌的相同用例,但从 Blob 收到以下错误 -

AuthenticationFailed
服务器无法验证请求。确保授权标头的值格式正确,包括签名。 请求ID:431d52db-a01e-0018-1265-1baaf5000000 时间:2023-11-20T03:57:51.1981101Z 签名不匹配。要签名的字符串

您能帮我了解如何生成要签名的字符串吗?我已遵循标准文档

© www.soinside.com 2019 - 2024. All rights reserved.