2012-12-01 159 views
0

在使用nodejs/azure和表服務編寫應用程序時,我們如何設置應該使用哪種類型的授權。共享密鑰(或)共享密鑰。蔚藍表服務認證

我們該如何設置?

+0

你可能無法。你爲什麼想要? – smarx

+0

我還沒有親身嘗試過node.js,但我相信如果您使用適用於Windows Azure的node.js SDK,它將爲您處理此問題。你可以從這裏下載:https://www.windowsazure.com/en-us/develop/downloads/。 HTH。 –

回答

1

這取決於你如何訪問表服務。如果您使用SDK,你可以做這樣的:

共享密鑰

var sharedKey = = new SharedKeyTable(storageAccount, storageAccessKey, usePathStyleUri); 
var tableService = azure.createTableService(null, null, null, sharedKey); 

共享密鑰精簡版

var sharedKeyLite = = new SharedKeyLiteTable(storageAccount, storageAccessKey, usePathStyleUri); 
var tableService = azure.createTableService(null, null, null, sharedKeyLite); 

Take a look at the code,你會看到共享密鑰會如果您省略身份驗證提供程序,則使用此方法

如果使用http.request你需要指定的授權頭類型:

Authorization="[SharedKey|SharedKeyLite] <AccountName>:<Signature>" 

所以,你的代碼將是這樣的:

var http = require('http'); 

function doSomethingWithTables() { 
    var settings = { 
     host: ..., 
     port: 80, 
     path: ..., 
     headers: {}, 
     method: 'GET' 
    }; 
    settings.headers['Authorization'] = 'SharedKeyLite myaccount:xxiofojpfzaopfiaz'; 

    var req = http.request(settings); 
    req.write(...); 
    req.on('response', function(res){ 
     ... 
    }); 
} 
+0

我沒有使用SDK。我正在使用node.js和Azure ......我該怎麼做? –

+0

我已經更新了我的答案。但是在構建自己的東西之前,你應該看看Node.js的SDK。 –