Share via

Authentication Error when accessing Files using Signed SAS URL obtained by from Javascript API

Jai Mohan | iLE 0 Reputation points
2023-08-03T04:34:30.54+00:00

This is the error when accessing the URL


<?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:058707dc-e01a-006b-19bf-c5c5f9000000
Time:2023-08-03T04:07:04.6473054Z</Message><AuthenticationErrorDetail>Signature did not match. String to sign used was r
2023-08-10T04:07:03Z
/file/*******/config/contents/1691035621111-Planet_zoo.pdf
https
2022-11-02
</AuthenticationErrorDetail></Error>



And this is the code block being used.


const account = "*******";

const accountKey = "*********************************************************";

const AZFSSignedURL = async (contentDirectory, fileName, shareName = shareName) => {

  const shareClient = serviceClient.getShareClient(shareName);
  const directoryClient = shareClient.getDirectoryClient(contentDirectory);
  const fileClient = directoryClient.getFileClient(fileName);
  const expiresOn = new Date();
  expiresOn.setDate(expiresOn.getDate() + 7); 
  const sasToken = generateFileSASQueryParameters(
{
  fileSystemName: shareName,
  shareName: fileClient.shareName,
  filePath: fileClient.name,
  permissions: "r", 
  expiresOn: expiresOn,
  protocol: SASProtocol.Https, 
  version:'2022-11-02'
},
credential
  );
  console.log(sasToken)
  const url = fileClient.url + "?" + sasToken.toString();
  return { success: true, url: url, error: false };
};

Azure Files
Azure Files

An Azure service that offers file shares in the cloud.


1 answer

Sort by: Most helpful
  1. Ramya Harinarthini_MSFT 5,371 Reputation points Microsoft Employee Moderator
    2023-08-03T12:30:40.97+00:00

    @Jai Mohan | iLE

    there is a similar sample code provided for generateBlobSASQueryParameters in the below article please validate against generateFileSASQueryParameters if that works for you.

    https://stackoverflow.com/questions/61530356/how-to-generate-an-azure-blob-url-with-sas-signature-in-nodejs-sdk-v12

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.