2017-08-16 57 views
-1

如果你正在使用PowerShell,你可以直接與連接的Node.js到Azure訂閱

$kv = Get-AzureRmKeyVault -ResourceGroupName $ResourceGroupName -VaultName $vaultName 

連接到Azure中Keyvault是否與node.js的類似的東西?將節點連接到Keyvault的最有效方法是什麼?

回答

0

是否與node.js的類似的東西?

否,它們是不同的。根據我的理解,密鑰庫是一種Azure資源。 Node.js是一個基於Google Chrome的JavaScript引擎(V8引擎)構建的服務器端平臺。 Azure爲用戶提供了連接Azure KeyVault的PowerShell。但是如果你想連接keyvault和Node.js.您應該爲Node.js使用Azure SDK。

認證

var KeyVault = require('azure-keyvault'); 
var AuthenticationContext = require('adal-node').AuthenticationContext; 

var clientId = "<to-be-filled>"; 
var clientSecret = "<to-be-filled>"; 
var vaultUri = "<to-be-filled>"; 

// Authenticator - retrieves the access token 
var authenticator = function (challenge, callback) { 

    // Create a new authentication context. 
    var context = new AuthenticationContext(challenge.authorization); 

    // Use the context to acquire an authentication token. 
    return context.acquireTokenWithClientCredentials(challenge.resource, clientId, clientSecret, function (err, tokenResponse) { 
    if (err) throw err; 
    // Calculate the value to be set in the request's Authorization header and resume the call. 
    var authorizationValue = tokenResponse.tokenType + ' ' + tokenResponse.accessToken; 

    return callback(null, authorizationValue); 
    }); 

}; 

更多這方面的信息,請參閱本link:Microsoft Azure SDK for Node.js - Key Vault

+0

我已經看過這個,但是我無法確認是否連接。我沒有收到任何錯誤,但有沒有一種方法可以使用它從已存在的保險庫輸出祕密?我不想創建保險庫或密鑰,我只想列出保險庫中的信息以確保我已連接。 – user3364161

+0

@ user3364161您可以列出密鑰庫中的所有祕密。你可以檢查SDK。 'client.setSecret(vaultUri,'mysecret','我的密碼',選項,函數(err,secretBundle)'。 –