SAS token works in Azure Storage Explorer but doesn't work with the SDK

Ivan 1 Reputation point
2021-09-01T20:20:03.987+00:00

I've received a SAS token that grants me access to a third party's blob container. If I use the full {container URL}?{token} URL unmodified in Azure Storage Explorer, I can browse its contents just fine. However, if I try the same using this minimal example using the Node.js SDK, it fails with.

Minimal example:

    const { BlobServiceClient } = require('@azure/storage-blob')  
  
    const account = 'thirdpartyblob'  
    const sas = '?<sas token>'  
    const url = `https://${account}.blob.core.windows.net/thecontainer${sas}`  
  
    const client = new BlobServiceClient(url)  
    async function main() {  
        let i = 1  
        const containers = client.listContainers()  
        for await (const container of containers) {  
            console.log(`Container ${i++}: ${container.name}`)  
        }  
    }  
  
    main()  

Error:

Uncaught RestError: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.  

Somewhere inside the error's details it mentions the signature not matching. How do I troubleshoot and resolve this issue?

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,428 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. deherman-MSFT 33,306 Reputation points Microsoft Employee
    2021-09-02T18:56:22.687+00:00

    @Ivan

    If they just gave you update to a specific container you will not be able to run listContainers. Instead you would need to run listBlobs. There is a very similar thread where a user faced this issue. Please check to see if it resolved your problem.

    Hope this helps. If you are still facing issue please share the SAS URL minus the signature and any personal information for us to review.

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments