0

I'm trying to interact with Azure China Resources with Nodejs.

But could not find out how to authenticate the application with Azure China with nodejs SDK.

Tried @azure/arm-storage

import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";

import { StorageManagementClient, StorageManagementModels, StorageManagementMappers } from "@azure/arm-storage";

const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];


msRestNodeAuth.interactiveLogin().then((creds) => {
  const client = new StorageManagementClient(creds, subscriptionId);
  client.operations.list().then((result) => {
    console.log("The result is:");
    console.log(result);
  });
}).catch((err) => {
  console.error(err);
});

Karl Xu
  • 315
  • 5
  • 15
  • The China region Azure offering is managed separately (you need to sign up specifically for it). – David Makogon May 23 '19 at 11:52
  • I'm voting to close this question as off-topic because this is a subscription sign-up topic. Not programming-related. – David Makogon May 23 '19 at 11:54
  • @DavidMakogon Humbly, I disagree. The question is about how to connect to an Azure Subscription in China region using Node SDK. Please see my answer below. – Gaurav Mantri May 23 '19 at 12:22
  • @GauravMantri - ah - I misinterpreted the question. Yes, the China (and Germany) offerings both use different API endpoints. – David Makogon May 23 '19 at 12:25

1 Answers1

1

To connect to Azure China, you will need to specify the environment. Please see the code below:

const msRestNodeAuth = require("@azure/ms-rest-nodeauth");
const Environment = require("@azure/ms-rest-azure-env").Environment;

const mooncake = Environment.ChinaCloud;

msRestNodeAuth.interactiveLogin({
  environment: mooncake
}).then((creds) => {
  console.log(creds);
}).catch((err) => {
  console.error(err);
});
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241