且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DocumentDB REST API - 授权令牌错误

更新时间:2022-05-03 07:05:56

我认为文档不正确.在他们说 resourceLink 的地方,他们实际上应该说 resource id.如果您查看 Node SDK 代码,这就是他们计算授权标头的方式(注意使用 resourceId):

I believe the documentation is incorrect. Where they say resourceLink, they should actually say resource id. If you look at the Node SDK code, this is how they are calculating the authorization header (notice the use of resourceId):

getAuthorizationTokenUsingMasterKey: function (verb, resourceId, resourceType, headers, masterKey) {
    var key = new Buffer(masterKey, "base64");

    var text = (verb || "").toLowerCase() + "
" +
               (resourceType || "").toLowerCase() + "
" +
               (resourceId || "") + "
" +
               (headers["x-ms-date"] || "").toLowerCase() + "
" +
               (headers["date"] || "").toLowerCase() + "
";

    var body = new Buffer(text, "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;
},

因此,如果您想列出数据库,因为没有资源 ID,您需要为 link 变量使用空字符串.同样,如果要列出数据库中的集合,链接实际上应该是数据库的 id(例如 dbs/00001 而不是 dbs/00001/colls).

So if you want to list the databases, because there is no resource id you will need to use an empty string for your link variable. Similarly, if you want to list collections in the database, the link should actually be the id of the database (e.g. dbs/00001 and not dbs/00001/colls).