簡體   English   中英

Azure:按照文檔完成后,使用Azure REST API的表acl GET不起作用

[英]Azure: Table acl GET using Azure REST API do not work when done as per documentation

我正在關注GET ACL表Azure存儲服務的身份驗證的Azure REST文檔。

以下是我正在執行的REST操作的代碼段。

//Input your Storage Account and access-key associated to it.
const yourStorageAccountName = '';
const accessKeyStorageAccount = '';
const Client = require('node-rest-client').Client;
const crypto = require("crypto");

async function getTableAcl() {
    let now = new Date();
    let nowUTC = now.toUTCString();
    let contentType = "application/json"
    // construct input value
    let stringToSign = `GET\n\n\n${nowUTC}\n/${yourStorageAccountName}/tablename\ncomp:acl`;
    let accesskey = accessKeyStorageAccount;
    // create base64 encoded signature
    let key = new Buffer(accesskey, "base64");
    let hmac = crypto.createHmac("sha256", key);
    hmac.update(stringToSign);
    let sig = hmac.digest("base64");
    console.log("SIGNATURE : " + sig);
    console.log("nowutc : " + nowUTC);
    let args = {
        headers: {
            "Authorization": "SharedKey " + yourStorageAccountName + ":" + sig,
            "Date": nowUTC,
            "x-ms-version": "2015-12-11"
        }
    };
    let restClient = new Client();
    restClient.get(`https://${yourStorageAccountName}.table.core.windows.net/tablename?comp=acl`, args, function (data, response) {
        console.log(JSON.stringify(data));
        //console.log(response);
    });
}

getTableAcl()

這里要注意的是, Azure表ACL文檔中沒有提到Content-Type,但是在Authorization標頭部分中卻給出了Content-Type。 因此,我在“ stringToSign”中將content-type保持為空,並且在REST調用中未提供Content-Type標頭。 我可能會丟失某些東西,但無法確定可能是什么。

在這種情況下,您是否可以誤導我,您可以告訴我嗎?

基本上,問題在於您正在正確生成規范化的資源字符串。

該文檔指出以下內容:

2009-09-19及更高版本Shared Key Lite和Table服務格式

此格式支持Table服務的所有版本的Shared Key和Shared Key Lite,以及Blob and Queue服務的2009-09-19版和更高版本以及File Service的2014-02-14版和更高版本的Shared Key Lite。 此格式與先前版本的存儲服務使用的格式相同。 按照以下格式構造CanonicalizedResource字符串:

  1. 以空字符串(“”)開頭,在斜杠(/)后面加上擁有所訪問資源的帳戶名稱。
  2. 附加資源的編碼URI路徑。 如果請求URI尋址資源的一部分,請附加適當的查詢字符串。 查詢字符串應包含問號和comp參數(例如,?comp = metadata)。 查詢字符串中不應包含其他任何參數。

基於此,您的stringToSign應該為:

let stringToSign = `GET\n\n\n${nowUTC}\n/${yourStorageAccountName}/tablename?comp=acl`;

試試看,它應該可以工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM