angular-azure-blob-service icon indicating copy to clipboard operation
angular-azure-blob-service copied to clipboard

Getting 403 on using SAS token generated programmatically from "azure-storage" npm module (azure storage SDK "generateSharedAccessSignature" method). Works fine with SAS token generated through azure portal.

Open piyush-upadhyay opened this issue 4 years ago • 0 comments

Getting this error in response when trying to upload -

<Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. </Message><AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail></Error>

Javacript function -

function getSASUri(containerName,blobName) {

        var accountName = config.StorageAccountName;
        var accountKey = config.StorageAccountKey;
        var blobService = azure.createBlobService(accountName, accountKey);

        var startDate = new Date();
        startDate.setDate(startDate.getDate() - 5);
        var expiryDate = new Date(startDate);
        expiryDate.setDate(startDate.getDate() + 10);

        var sharedAccessPolicy = {
            AccessPolicy: {
                Permissions: 'rwdlacup',
                Start: startDate,
                Expiry: expiryDate
            }
        };

        let token = blobService.generateSharedAccessSignature(containerName, blobName, sharedAccessPolicy);
        var sasUrl = blobService.getUrl(containerName, blobName, token);

        return {
            token : token,
            sasUrl : sasUrl
        };
    };

piyush-upadhyay avatar Jul 24 '20 15:07 piyush-upadhyay