Node azure blobService.generateSharedAccessSignature () returns invalid token

I'm trying to create a shared signature using the azure node SDK, but the returned token doesn't work / doesn't have some parameters.

Im creating a marker with:

app.get('/node-api/get-azure-token', (req, res, next) => {
  var blobService = azure.createBlobService(myStorageAccount, myAccessKey);
  var container = 'my-azure-container-name';
  var startDate = new Date();
  var expiryDate = new Date(startDate);
  expiryDate.setMinutes(startDate.getMinutes() + 10);
  startDate.setMinutes(startDate.getMinutes() - 5);

  var sharedAccessPolicy = {
    AccessPolicy: {
        ServiceVersion: '2016-05-31',
        Permissions: azure.BlobUtilities.SharedAccessPermissions.READ + azure.BlobUtilities.SharedAccessPermissions.WRITE + azure.BlobUtilities.SharedAccessPermissions.DELETE + azure.BlobUtilities.SharedAccessPermissions.LIST + azure.BlobUtilities.SharedAccessPermissions.ADD + azure.BlobUtilities.SharedAccessPermissions.CREATE,
        Start: startDate,
        Expiry: expiryDate,
        Protocols: 'https,http'
    }
};

    const key = blobService.generateSharedAccessSignature(container, req.query.bloburi, sharedAccessPolicy);

    res.send(key);
});

      

Error "The server was unable to authenticate the request. Make sure the authorization header value is well formed, including the signature. 'Is thrown when using the generated sas character.

Has anyone faced this problem?

+3


source to share


1 answer


I just got it! The order of permissions in the AccessPolicy object should be in the order shown here: https://docs.microsoft.com/en-us/rest/api/storageservices/Constructing-a-Service-SAS?redirectedfrom=MSDN



+1


source







All Articles