2012-12-01 161 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。 –