【问题标题】:Azure Server failed to authenticate the request. Make sure the value of the authorization header is formed correctly including the signatureAzure 服务器未能对请求进行身份验证。确保授权标头的值格式正确,包括签名
【发布时间】:2021-09-19 00:52:38
【问题描述】:

enter code here我正在尝试使用 javascript 下载存储在 azure blob 中的文件并收到此错误。

这是我的代码

function getUrlOfAttachmentFileFromBlob(new_fileurl,new_fileName) {
  var fileHyperlink = '';
  var blobUri = 'https://' + 'Storage_Account_Name' + '.blob.core.windows.net';
  var containerName = 'trial';
  var sas_token = 'sastoken' ;
    
  var blobService = AzureStorage.Blob.createBlobServiceWithSas(blobUri, sas_token);
  //.withFilter(new AzureStorage.Blob.ExponentialRetryPolicyFilter());

  var downloadLink = blobService.getUrl(new_fileName, new_fileurl.replace('/'+containerName+'/',''), sas_token);

  if (downloadLink != null)
  {
      alert("Link " + downloadLink);
      downloadURI(downloadLink, new_fileName);
  }
}

我没有在这里生成共享签名和 sas 令牌。我直接将 sas 令牌分配给变量。

当我尝试在浏览器中打开链接时出现此错误

AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:504f2ef5-f01e-0021-0e02-74e194000000
Time:2021-07-08T14:09:47.9951927Z</Message><AuthenticationErrorDetail>sp is mandatory. Cannot be empty</AuthenticationErrorDetail></Error>

我没有在我的代码中传递任何标题。

我在这里缺少什么?

SAS 令牌 = ?sp=r&st=2021-07-08T12:19:08Z&se=2021-07-08T20:19:08Z&spr=https&sv=2020-02-10&sr=c&

没有签名部分。

这就是我从 geturl 函数得到的结果 =

?%3Fsv=2020-02-10&ss=bfqt&srt=sco&sp=rwdlacuptfx&se=2021-07-11T12%3A30%3A23Z&st=2021-06-11T04%3A30%3A23Z&spr=https%2chttp&

我想我没有从这个函数中得到正确的 url,所以我用这个替换了那行

const downloadLink = blobUri +'/' + containerName + '/' + new_fileName + sas_token;

但仍然无法下载文件。但没有收到身份验证错误。

谢谢...

【问题讨论】:

标签: javascript azure azure-blob-storage


【解决方案1】:

您收到此错误的原因是您的 SAS 令牌无效。如果您仔细查看错误消息,您将看到以下内容:

<AuthenticationErrorDetail>sp is mandatory. Cannot be empty</AuthenticationErrorDetail>

基本上您的 SAS 令牌缺少 signed permissions (sp) 参数。请检查您的 SAS 令牌并确保其格式正确。

【讨论】:

  • 我提供了正确的 sas 令牌。但是我没有从 Azure blob 存储库中的这个函数获得正确的 sas 令牌。 var downloadLink = blobService.getUrl(new_fileName, new_fileurl.replace('/'+containerName+'/',''), sas_token);
  • 您能否编辑您的问题并包含 SAS 令牌?您可以混淆 SAS 令牌的 sig 部分。
  • 也分享下载链接。
  • 我已经编辑了我的问题,包括 sas 令牌。谢谢
  • 谢谢。您的 getUrl 函数肯定有问题。这是您编写的自定义函数吗?我不记得 SDK 中有这个功能。
猜你喜欢
  • 2021-03-21
  • 1970-01-01
  • 2014-03-18
  • 2020-01-29
  • 2014-09-19
  • 2016-04-04
  • 1970-01-01
  • 1970-01-01
  • 2016-01-31
相关资源
最近更新 更多