Azure / Azure/azure-storage-node

generateBlobSASQueryParameters

Open
#731 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
482
Forks
227
PR merge metrics
No merged PRs in 30d

Description

> For latest features support, please switch to [Azure Storage JavaScript SDK V10](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage).

### Which service(blob, file, queue, table) does this issue concern?
blob

### Which version of the SDK was used?
"@azure/storage-blob":"^12.12.0"

### What's the Node.js/Browser version?
Edge / Node.js 16.9.0

### What problem was encountered?
generateBlobSASQueryParameters is not geneating correct SAS url for blobs, the signature generated is invalid as it doesn't add the blob string

AuthenticationFailed
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:3ae15bdc-901e-0008-435e-245108000000 Time:2023-01-09T19:10:25.9697563Z
Signature did not match. String to sign used was r 2023-01-09T19:10:07Z 2023-01-09T19:11:34Z /blob/cs2100320024a648bca/azureblob-skillset-2-image-projection 2021-10-04 c

In the error message in string is the location of container , the path of the blob is not specified/added even though it is passed as parameter.
### Steps to reproduce the issue?
const { BlobServiceClient, BlobClient, generateBlobSASQueryParameters,BlobSASSignatureValues, BlobSASPermissions ,StorageSharedKeyCredential} = require("@azure/storage-blob");

const account_name = 'XXX';
const account_key = 'XXXX';
const container_name = 'XXXXX'

module.exports = async function (context, req) {

blob_name = 'normalized_images_0.jpg';
// Reading inputs from HTTP Request
const id = (req.query.id || (req.body && req.body.id));
console.log("+++++")
console.log(id)
console.log("+++++")
blob_name = id+'/'+ blob_name
console.log(blob_name)
sas_token = get_blob_sas(account_name,account_key, container_name, blob_name)
console.log(sas_token)
url = 'https://'+account_name+'.blob.core.windows.net/'+container_name+'/'+blob_name+'?'+sas_token

// context.log(url);
// console.log(url)

context.res = {
// status: 200, /* Defaults to 200 */
headers: {
"Content-type": "application/text"
},
body: { document: url}
};

};

const get_blob_sas = (account_name,account_key, container_name, blob_name) => {

sharedKeyCredential = new StorageSharedKeyCredential(account_name, account_key);
console.log(blob_name);
console.log(container_name)
location_string = container_name +'/'+blob_name
console.log(location_string)

const blobSAS = generateBlobSASQueryParameters({
container_name,
blob_name,
permissions: BlobSASPermissions.parse("r"), // Required
startsOn: new Date(),
expiresOn: new Date(new Date().valueOf() + 86400) // Required. Date type
},
sharedKeyCredential
).toString();


console.log("*************")
console.log(blobSAS)
return blobSAS;
}

### Have you found a mitigation/solution?
No

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.