首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure: SDK生成的共享访问签名在浏览器中不起作用

Azure: SDK生成的共享访问签名在浏览器中不起作用
EN

Stack Overflow用户
提问于 2020-02-22 17:30:29
回答 1查看 383关注 0票数 1

我正在通过CloudStorageAccount生成一个SAS,如下所示:

代码语言:javascript
复制
var sharedAccessAccountPolicy = new SharedAccessAccountPolicy
{
     Permissions = SharedAccessAccountPermissions.Read | SharedAccessAccountPermissions.Write,
     Services = SharedAccessAccountServices.Blob,
     ResourceTypes = SharedAccessAccountResourceTypes.Object,
     SharedAccessExpiryTime = DateTime.UtcNow.AddYears(1),
     Protocols = SharedAccessProtocol.HttpsOnly
};

return cloudStorageAccount.GetSharedAccessSignature(sharedAccessAccountPolicy);

问题是,当我将SAS附加到blob并将产生的字符串粘贴到浏览器中时,我得到的是带有AuthenticationFailed (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature)细节的Signature did not match

如果我在Azure门户(或Azure )上生成一个SAS,那么SAS在浏览器中工作。我注意到SDK生成的SAS与门户生成的SAS之间存在差异。

  • 门户显示?sv=2019-02-02,而SDK显示?sv=2018-03-28。是否有方法在SDK中手动配置它以匹配门户?
  • 门户将:添加到%3A到期日期,而SDK添加%3A。这有什么区别吗?

下面是SDK提供的URL和SAS令牌:

https://myaccount.blob.core.windows.net/mycontainer/giphy.gif?sv=2018-03-28&sig=<sigValue>&spr=https&st=2020-02-22T18%3A02%3A12Z&se=2021-02-22T18%3A02%3A12Z&srt=o&ss=b&sp=rw

网页来源:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?><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:c662b297-e01e-0065-19ac-e9e3d0000000
Time:2020-02-22T18:17:24.7226395Z</Message><AuthenticationErrorDetail>Signature did not match. String to sign used was myaccount
rw
b
o
2020-02-22T18:02:12Z
2120-02-22T18:02:12Z

https
2018-03-28
</AuthenticationErrorDetail></Error>

这是门户网站生成的:

?sv=2019-02-02&ss=b&srt=o&sp=rw&se=2021-02-23T02:18:59Z&st=2020-02-22T18:18:59Z&spr=https&sig=<sigValue>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-22 19:31:17

在花了很多时间试图找出根本原因之后,我自己找到了答案。出于某种原因,必须将$spr=https子字符串添加到令牌的末尾。当客户端SDK生成令牌时,该子字符串将显示在开始处,并导致身份验证问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60354839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档