【问题标题】:Connect node.js to Azure Subscription将 node.js 连接到 Azure 订阅
【发布时间】:2017-08-25 17:02:36
【问题描述】:

如果您使用的是 Powershell,则可以使用

直接连接到 Azure Keyvault
$kv = Get-AzureRmKeyVault -ResourceGroupName $ResourceGroupName -VaultName $vaultName

node.js 有类似的东西吗?将节点连接到 Keyvault 的最有效方法是什么?

【问题讨论】:

    标签: node.js azure azure-powershell


    【解决方案1】:

    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

    【讨论】:

    • 我实际上已经看过这个,但我无法确认我是否正在连接。我没有收到任何错误,但有没有办法可以使用它从已经存在的保险库中输出机密?我不想创建保险库或密钥,我只想列出保险库中的信息以确保我已连接。
    • @user3364161 您可以列出密钥保管库中的所有机密。你可以检查SDK。 client.setSecret(vaultUri, 'mysecret', 'my password', options, function (err, secretBundle).
    猜你喜欢
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-11
    • 2018-09-20
    • 2013-01-18
    • 2019-11-22
    相关资源
    最近更新 更多