2

Trying to follow the samples from https://github.com/Azure/ms-rest-nodeauth

When passing authresponse to a client to generate a client to ping resources, I end up getting:

Error: credentials argument needs to implement signRequest method

I am trying to read through the documents to see if I need to sign the token's I am getting back from the SDK/Azure AD, but the documentation for the new SDK doesnt show anything

2 Answers 2

3

Figured it out, have to call .credentials on the authresponse

Sign up to request clarification or add additional context in comments.

Comments

1

Adding the code, using @azure/arm-billing, in case the full code file is helpful.

// 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);
}); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.