'need to fetch the particular entity from azure storage table using partition and row key. But getting 403

I need to fetch a particular entity from storage table using shared key lite. I'm using following code

const timestamp = (new Date()).toUTCString();
const encodedUriPath = `${TableName}(PartitionKey='${partition_key}', RowKey='${row_key}')`;
const stringToSign = timestamp + '\n/' + tableService.storageAccountName + '/' + encodedUriPath;
const sharedKeyLite = crypto.createHmac('sha256', Buffer.from(accessKey, 'base64'))
  .update(stringToSign)
  .digest('base64');
const endPoint = `https://${storageAccountName}.table.core.windows.net/${encodedUriPath}`;
return backOff(() => new Promise<Entity>((resolve, reject) => {
  request.get({
    'headers': {
      'Authorization': 'SharedKeyLite ' + storageAccountName + ':' + sharedKeyLite,
      'x-ms-date': timestamp,
      'x-ms-version': storageApiVersion,
      'Accept': 'application/json',
      'Prefer': 'return-content'
    },
    'url': endPoint,
    'json': true
  }, function (err, result) {
    if (err) {
      return reject(err);
    }
    if (result.statusCode === 404) {
      return resolve(null);
    }
    if (result.statusCode !== 200) {
      return reject(ODataToError(result.body['odata.error']));
    }
  });

Here I'm getting 403 error saying the signature is invalid. Can anyone suggest the mistake done in string to sign. I doubt that.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source