【问题标题】:ms-rest-nodeauth (azure-sdk-for-js) : Error: credentials argument needs to implement signRequest methodms-rest-nodeauth (azure-sdk-for-js) :错误:凭据参数需要实现 signRequest 方法
【发布时间】:2019-07-02 16:09:06
【问题描述】:

尝试追踪来自https://github.com/Azure/ms-rest-nodeauth的样本

当将 authresponse 传递给客户端以生成客户端以 ping 资源时,我最终得到:

错误:凭据参数需要实现signRequest方法

我正在尝试通读文档以查看是否需要签署我从 SDK/Azure AD 取回的令牌,但新 SDK 的文档没有显示任何内容

【问题讨论】:

    标签: azure-node-sdk


    【解决方案1】:

    想通了,必须在 authresponse 上调用 .credentials

    【讨论】:

      【解决方案2】:

      添加代码,使用@azure/arm-billing,以防完整代码文件有帮助。

      // auth.json
      // Create auth file with Azure CLI:`az ad sp create-for-rbac --sdk-auth > auth.json`
      {
      "clientId": "",
      "clientSecret": "",
      "subscriptionId": "",
      "tenantId": "",
      "activeDirectoryEndpointUrl": "https://login.microsoftonline.com",
      "resourceManagerEndpointUrl": "https://management.azure.com/",
      "activeDirectoryGraphResourceId": "https://graph.windows.net/",
      "sqlManagementEndpointUrl": "https://management.core.windows.net:8443/",
      "galleryEndpointUrl": "https://gallery.azure.com/",
      "managementEndpointUrl": "https://management.core.windows.net/"
      }
      
      // index.js
      const msRest = require("@azure/ms-rest-js");
      const msRestAzure = require("@azure/ms-rest-azure-js");
      const msRestNodeAuth = require("@azure/ms-rest-nodeauth");
      const armBilling = require("@azure/arm-billing");
      const path = require('path');
      
      // list billing information
      const lists = async (client) => {
      
          try {
              let lists = [];
      
              const enrollmentAccounts = await client.enrollmentAccounts.list();
              lists.push(enrollmentAccounts);
      
              const billingPeriods = await client.billingPeriods.list();
              lists.push(billingPeriods);
      
              const invoices = await client.invoices.list();
              lists.push(invoices);
      
              return lists;
          } catch (err) {
              console.log(err);
              throw (err);
          }
      
      }
      
      // sample auth file created from Azure CLI - removed PII
      const authenticationFile = path.join(__dirname, "./auth.json");
      const options = {
          filePath: authenticationFile
      };
      
      // get subscriptionId from auth file
      const subscriptionIdFromAuthFile = require('./auth.json').subscriptionId;
      
      // authenticate and getting billing information
      msRestNodeAuth.loginWithAuthFileWithAuthResponse(options).then(async (response) => {
          
          console.log("authenticated");
          
          // --- CHANGE response parameter to -> response.credentials
          const client = new armBilling.BillingManagementClient(response.credentials, subscriptionIdFromAuthFile);
          console.log("client created");
          
          const results = await lists(client);
          console.log(`The result is:${JSON.stringify(results)}`);
      
      }).catch((err) => {
          console.error(err);
      }); 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-01
        • 2020-10-18
        • 2020-12-13
        • 2021-07-10
        • 2021-10-14
        • 2018-07-29
        相关资源
        最近更新 更多