MS-Rest-Nodeauth(Azure-SDK-For-JS):错误:凭据参数需要实现SignRequest方法



试图从https://github.com/azure/ms-rest-nodeauth

中关注样本

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

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

我正在尝试阅读文档,以查看我是否需要签署令牌,我从SDK/Azure AD中返回,但是新SDK的文档并未显示任何内容

弄清楚了,必须在authResponse上拨打.credentials

使用@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);
}); 

最新更新