How to Use Azure Storage SASToken in REST Call

solvingJ Source

An Azure API call returns a SAS token that can be used to query a storage table (example with values changed below).

With the Azure Storage SDK for Java, I am able to pass this whole token into the constructor of a credential object like so:

new StorageCredentialsSharedAccessSignature(tokenString)

That credential object is then somehow used to authenticate for the "CloudTableClient" object:

CloudTableClient tableClient = new CloudTableClient(
    new URI(tableEndpoint),
    new StorageCredentialsSharedAccessSignature(tokenString))

However, I'm hoping someone can help me use the token to construct a much simpler REST call. I was unable to reverse-engineer the CloudTableClient to figure out what to do with the tokenString. I've tried putting it in the URL and authorization header, but it's mostly trial and error. Any help would be appreciated.

Example Token format:

"sasToken" : "?sv=2015-04-05&tn=WADMetricsPT1HP10DV2S20160704&spk=%3A002Fsubscriptions%3A123456789012%3A12345678%3A12345678%3A1234567890123456%3A002FresourceGroups%3A002FRGName001%3A002Fproviders%3A002FMicrosoft%3A002ECompute%3A002FvirtualMachines%3A002FAzureWinServer&epk=%3A002Fsubscriptions%3A123456789012%3A002D54c4%3A12345678%3A12345678%3A1234567890123456%3A002FresourceGroups%3A002FRGName001%3A002Fproviders%3A002FMicrosoft%3A002ECompute%3A002FvirtualMachines%3A002FAzureWinServer&sig=SOMEFAKESIGNATURE123456a%2SOMEFAKESIGNATURE12345%3D&se=2016-08-18T10%3A57%3A58Z&sp=r"


answered 2 years ago solvingJ #1

The answer is to simply put it on the end of the URL, and append any additional query parameters you have after it. For example, an api-version parameter is required in the URL, so at this time you would add:

&api-version=2015-04-05 .

Also, use no authorization header of the request.

comments powered by Disqus