Unable to connect to DocDB via REST API.
getting following error message
{ "code": "unauthorized", "message": "the input authorization token can't serve request. please check expected payload built per protocol, , check key being used. server used following payload sign: 'get\ndbs\n\nmon, 16 feb 2015 23:01:28 gmt\n\n'" }
all trying list dbs under account using nodejs
here code:
i have replaced original master code , doc db url security purpose
var rest = require('restler');
var targeturl = "https://xyzdocdb.documents.azure.com/dbs";
var verb = "get";
var resourceid = "";
var resourcetype = "dbs";
var headers = ["'x-ms-date' : 'mon, 16 feb 2015 23:01:28 gmt'", "'date' : 'wed, 18 feb 2015 05:59:28 gmt'"];
var masterkeybase64 = "my master key";
var authheader = getauthorizationheader(verb, resourceid, resourcetype, headers, masterkeybase64);
var options = { "method": "get", "headers":{"authorization": authheader, "x-ms-date": "mon, 16 feb 2015 23:01:28 gmt", "content-type":"application/json"} };
console.log(options);
// send rest request
dbsvc = rest.request( targeturl, options );
dbsvc.on( 'complete', function(result, response)
{ // have reply
// fetch json response
retjson = json.parse(response.raw);
helper.httpjsonresponse(httpres,statuscode,retjson);
});
// function getauthorizationheader azure document
var getauthorizationheader = function(verb, resourceid, resourcetype, headers, masterkeybase64) { var key = new buffer(masterkeybase64, "base64"); var stringtosign = (verb || "") + "\n" + (resourcetype || "") + "\n" + (resourceid || "") + "\n" + (headers["x-ms-date"] || "") + "\n" + (headers["date"] || "") + "\n"; var body = new buffer(stringtosign.tolowercase(), "utf8"); var signature = crypto.createhmac("sha256", key).update(body).digest("base64"); var mastertoken = "master"; var tokenversion = "1.0"; return "type=" + mastertoken +"&ver=" + tokenversion + "&sig=" + signature; }
an full working example using nodejs useful rather bits , pieces of code.
thank you
-rk
Microsoft Azure > Azure Cosmos DB
Comments
Post a Comment