将 node.js 连接到 Azure 订阅
Connect node.js to Azure Subscription
如果您使用的是 Powershell,则可以使用
直接连接到 Azure Keyvault
$kv = Get-AzureRmKeyVault -ResourceGroupName $ResourceGroupName -VaultName $vaultName
有没有和node.js类似的东西?将节点连接到 Keyvault 的最有效方法是什么?
Is there something similar with node.js?
不,它们是不同的。根据我的理解,Key Vault 是一种 Azure 资源。 Node.js 是建立在 Google Chrome 的 JavaScript 引擎(V8 引擎)之上的服务器端平台。 Azure 为用户提供了 powershell 来连接 Azure KeyVault。但是如果你想用 Node.js 连接 keyvault。您应该为 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。
如果您使用的是 Powershell,则可以使用
直接连接到 Azure Keyvault$kv = Get-AzureRmKeyVault -ResourceGroupName $ResourceGroupName -VaultName $vaultName
有没有和node.js类似的东西?将节点连接到 Keyvault 的最有效方法是什么?
Is there something similar with node.js?
不,它们是不同的。根据我的理解,Key Vault 是一种 Azure 资源。 Node.js 是建立在 Google Chrome 的 JavaScript 引擎(V8 引擎)之上的服务器端平台。 Azure 为用户提供了 powershell 来连接 Azure KeyVault。但是如果你想用 Node.js 连接 keyvault。您应该为 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。