Azure Client Runtime for AutoRest Generated Node.js Libraries

3.0.2 · deprecated · verified Tue Apr 21

ms-rest-azure served as the foundational client runtime for Node.js Azure client libraries generated using the AutoRest toolchain. It provided essential infrastructure for handling HTTP requests, error responses, tracing, and Azure-specific authentication mechanisms such as Device Token, Service Principal, and Managed Identity. The package (version 3.0.2, last published approximately four years ago) was part of the older `azure-sdk-for-node` repository. As of March 2023, this package, along with many others in its repository, has been officially deprecated. The Azure SDK team has transitioned to a new generation of SDKs (`@azure/*` packages) that offer isomorphic capabilities (browser and Node.js support), consistent design guidelines, and native TypeScript support. Users are strongly encouraged to migrate to the newer `@azure/core-client` and `@azure/identity` packages for modern Azure development.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates authenticating with Azure using a service principal and listing subscriptions, typical for older SDK clients.

import { loginWithServicePrincipalSecret } from 'ms-rest-azure';
import { SubscriptionClient } from '@azure/arm-subscriptions'; // Example: using a client that depends on ms-rest-azure

const clientId = process.env.AZURE_CLIENT_ID ?? '';
const secret = process.env.AZURE_CLIENT_SECRET ?? '';
const domain = process.env.AZURE_TENANT_ID ?? ''; // Also known as tenantId
const subscriptionId = process.env.AZURE_SUBSCRIPTION_ID ?? '';

async function authenticateAndListSubscriptions() {
  if (!clientId || !secret || !domain || !subscriptionId) {
    console.error('Please set AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID, and AZURE_SUBSCRIPTION_ID environment variables.');
    return;
  }

  try {
    console.log('Attempting to log in with Service Principal...');
    const credentials = await loginWithServicePrincipalSecret(clientId, secret, domain);
    console.log('Successfully authenticated.');

    const client = new SubscriptionClient(credentials);
    const subscriptions = await client.subscriptions.list();

    console.log('Azure Subscriptions:');
    for await (const sub of subscriptions) {
      console.log(`- ${sub.displayName} (${sub.subscriptionId})`);
    }
  } catch (err) {
    console.error('Authentication or API call failed:', err);
  }
}

authenticateAndListSubscriptions();

view raw JSON →