2017-05-07 71 views
0

我試圖調用使用node.js SDK notificationHub服務API。我生成的密鑰「令牌」下面這個頁面的documentation天青:如何進行身份驗證服務API調用

然後在我node.js程序,我有以下代碼:

const client = new notificationHubsClient(AZURE_KEY, AZURE_SUBSCRIPTION_ID); 
    console.log('the client', client); 

但是我得到這個錯誤:

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: credentials argument needs to implement signRequest method 

到目前爲止我使用我以前生成的令牌不能確定是否正確,從文檔:

var client = new notificationHubsClient(credentials, 'your-subscription-id'); 

回答

0

根據您的描述,我想你正在使用azure-sdk-for-node。而根據the documentation here,我們應該產生這樣的憑據:

const Azure = require('azure'); 
const MsRest = require('ms-rest-azure'); 

MsRest.loginWithServicePrincipalSecret(
    'clientId or appId', 
    'secret or password', 
    'domain or tenant', 
    (err, credentials) => { 
    if (err) throw err 

    var client = new notificationHubsClient(credentials, 'your-subscription-id'); 
    } 
); 
+0

根據這個文件的第三種方法做到這一點,我並不想用代碼中沒有提供我的密碼,但第一方法是使用我所遵循的protal來獲得令牌。我不確定什麼是證書,我認爲它只是令牌。 – user3462064

+0

你可以存儲在環境變量中的祕密,而不是在你的項目的源代碼。查看示例代碼:https://github.com/Azure/azure-sdk-for-node/blob/master/examples/ARM/compute/vm-sample.js#L23 –

+0

呀,真'.env'是真的不錯,但我的問題是你如何使用它生病了第一種方法使用門脈,但如果我沒有得到很好的答案將採用第三種方法,並接受你的答案,謝謝。 – user3462064

相關問題