gpt4 book ai didi

c# - Azure 共享访问签名 - 签名不匹配

转载 作者:可可西里 更新时间:2023-11-01 07:51:15 26 4
gpt4 key购买 nike

我收到此错误:

<Error>
<Code>AuthenticationFailed</Code>
<Message>
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:6c3fc9a8-cdf6-4874-a141-10282b709022 Time:2014-07-30T10:48:43.8634735Z
</Message>
<AuthenticationErrorDetail>
Signature did not match. String to sign used was rwl 2014-07-31T04:48:20Z /acoustie/$root 2014-02-14
</AuthenticationErrorDetail>
</Error>

当我生成 sas(共享访问签名)然后将该 sas 粘贴到容器 uri 末尾到浏览器中时,我会得到它。这是生成的 sas 的完整地址:

https://acoustie.blob.core.windows.net/mark?sv=2014-02-14&sr=c&sig=E6w%2B3B8bAXK8Lhvvr62exec5blSxsA62aSWAg7rmX4g%3D&se=2014-07-30T13%3A30%3A14Z&sp=rwl

我已经搜索过SO和Google,并尝试了很多组合,据我所知,我做的一切都是正确的,我知道我不是,我只是看不到它......真的希望有人可以帮助:-\

需要明确的是,我在容器上生成 sas,而不是特定的 blob,也不是在根容器上。对 Blob 的访问定义为公共(public) Blob。我的最终目标是简单地允许使用 sas 写入容器,同时“调试”我已向 SharedAccessBlobPolicy 添加了大部分权限。

我尝试在容器名称的 beginning and ending 处添加\。没有变化。

这是我用来生成 sas 的代码:

    var blobClient = storageAccount.CreateCloudBlobClient();
//Get a reference to the blob container
var container = blobClient.GetContainerReference(containerName);

// Do not set start time so the sas becomes valid immediately.
var sasConstraints = new SharedAccessBlobPolicy
{
SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(30),
Permissions = SharedAccessBlobPermissions.Write
| SharedAccessBlobPermissions.Read
| SharedAccessBlobPermissions.List,
};

var sasContainerToken = container.GetSharedAccessSignature(sasConstraints);

//Return the URI string for the container, including the SAS token.
var sas = string.Format("{0}{1}", container.Uri.AbsoluteUri, sasContainerToken);
Logger.Debug("SAS: {0}", sas);
return sas;

它生成了一个签名,但它似乎不是一个有效的签名。

我尝试过不同的容器,更改访问策略,有或没有开始时间,将到期时间延长到从现在起超过 12 小时(我位于 UTC+10 时区),这似乎并不重要我更改它会导致相同的“签名不匹配”错误。

我什至尝试过使用旧版本的“WindowsAzure.Storage”,所以我现在尝试了 4.2 和 4.1。即使在不同的浏览器中尝试了 uri,确实应该没有什么区别,但是嘿...

非常感谢任何建议:-)

最佳答案

简短回答:

comp=list&restype=container 添加到您的 SAS URL,您应该不会收到此错误。

长答案:

基本上,从您的 SAS URL 来看,Azure 存储服务无法识别您尝试访问的资源是 Blob 还是容器,并假定它是 Blob。由于它假定资源类型是 blob,因此它使用 $root blob 容器进行 SAS 计算(您可以从错误消息中看到)。由于 SAS 是针对 mark blob 容器计算的,因此您会收到此签名不匹配错误。通过指定 restype=container,您将告诉存储服务将资源视为容器。根据 REST API 规范,需要 comp=list

关于c# - Azure 共享访问签名 - 签名不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25038429/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com