Monday, 8 May 2017

Node azure blobService.generateSharedAccessSignature() returns an incorrect token

I'm trying to generate a shared access signature with the azure node SDK, but the returned token is not working/missing some params.

Im creating the token 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);
});

The error 'Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.' is thrown when using the generated sas token.

Has anyone come across this issue?



via Tlouth19

No comments:

Post a Comment