Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Server failed to authenticate the request. Make sure the value of the authorization header is formed correctly including the signature

enter code hereI am trying to download the file stored in azure blob using javascript and getting this error.

Here is my code

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);
  }
}

I am not generating shared signature and sas token here. I am directly assigning the sas token to the variable.

When I try to open the link in browser I am getting this error

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>

I am not passing any headers in my code.

What i am missing here?

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

Without sig part.

This is what I am getting from geturl function =

?%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&

I think I am not getting correct url from this function, so i replaced that line with this

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

But still not able to download the file. But not getting authentication error.

Thank you...

like image 873
amrutha varshini Avatar asked Dec 06 '25 20:12

amrutha varshini


2 Answers

The reason you're getting this error is because your SAS token is not valid. If you look closely at the error message you will see the following:

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

Essentially your SAS token is missing signed permissions (sp) parameter. Please check your SAS token and make sure that it is correctly formed.

like image 56
Gaurav Mantri Avatar answered Dec 08 '25 08:12

Gaurav Mantri


I resolve the related issues on shared access signature (SAS) Allowed resource types by clicking Service

Container

Object and finally generate new token works fine.

like image 21
Temam Beshir Avatar answered Dec 08 '25 10:12

Temam Beshir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!