0
votes

I'm trying to make a GET request to Azure Table REST API with Postman. I can make a working request with a C# program I found, but when I try to copy the same information into the Postman request it return the followign error:

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

With the C# program I generate my UTC time and my Authorization code. The program will give me the following output:

x-ms-date: Fri, 01 Nov 2019 10:13:26 GMT

Authorization: SharedKeyLite username:e4IREMOVEDSOMELETTERST4Ag=

Request URI: https://username.table.core.windows.net/MainTable(PartitionKey='akey',RowKey='130')

The generated output works in the C# program, because when I use:

    result = await Client.GetAsync(requestUri);

The result will give me the information of (akey, 130). When I pass them into postman it will still give me an error. I do update the date in postman whenever I make a new authorized string.

My postman setup is as follows: postman

I eventually want to make this request with the ESP32, so it might be a bit unrelated, but the ESP is giving me the same error. Any tips on setting the headers correct either for Postman or the ESP are appreciated.

2

2 Answers

2
votes

to make this work first create two variables in your environment :

{{utcDate}}
{{authToken}}

Then create a new Get request and setup your headers like this :

x-ms-version             2015-12-11

x-ms-date                {{utcDate}}

Authorization            SharedKey resourceName:{{authToken}}

DataServiceVersion       3.0;NetFx

MaxDataServiceVersion    3.0;NetFx

Accept                   application/json;odata=nometadata

Finally, define a Pre-request Script :

var now = new Date().toUTCString();
pm.environment.set("utcDate", now);
var hcar = "/resourceName/TableName";
var verb = request.method;
var cntMd5 = "";
var cntType = "";
var mKey="<Your service key goes here>";

var text = verb + "\n" + (cntMd5 || "") + "\n" + (cntType || "") + "\n" + now + "\n" + hcar;

var key = CryptoJS.enc.Base64.parse(mKey);
var signature = CryptoJS.HmacSHA256(text, key);
var base64Bits = CryptoJS.enc.Base64.stringify(signature);
pm.environment.set("authToken", base64Bits);

The reason for the variables is, authToken because you need a place holder to store the calculated token, utcDate because the same date in your header must be used to calculate your token.

0
votes

I found that the problem was within Postman itself. There has been an ongoing issue with the automatic URL encoding. When I went directly to the MainTable the code of Mauricio worked.