From 6b586ed608830e8da526cb287f5da79791cd405c Mon Sep 17 00:00:00 2001 From: colawwj Date: Tue, 22 Feb 2022 10:50:16 +0800 Subject: [PATCH 1/3] update-documentation-use.md --- documentation/how-to-use.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/documentation/how-to-use.md b/documentation/how-to-use.md index bbaaf78b8b6f..31e102effe68 100644 --- a/documentation/how-to-use.md +++ b/documentation/how-to-use.md @@ -18,9 +18,7 @@ In this document, we will give a brief introduction on how to use the JavaScript 1. Install dependencies. ``` - // install the nodeauth packages to do the authentication work. - npm install @azure/ms-rest-nodeauth - // or install @azure/identity, if you would like to use @azure/identity to do the authentication work. + // install the @azure/identity packages to do the authentication work. npm install @azure/identity // Then install your target try out package, you can install the latest published with @@ -35,24 +33,25 @@ In this document, we will give a brief introduction on how to use the JavaScript 1. Create a ts file (free name and copy follow code into this file) eg: test_1.ts eg: ``` - const msRestNodeAuth = require("@azure/ms-rest-nodeauth"); + const DefaultAzureCredential = require("@azure/identity"); const { TargetManagementClient } = require("@azure/arm-target"); // must same as dependencies const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; - msRestNodeAuth.interactiveLogin().then((creds) => { - const client = new TargetManagementClient(creds, subscriptionId); - client.operations.list().then((result) => { // you can test that you need test operation - console.log("The result is:"); - console.log(result); - }); - }).catch((err) => { - console.error(err); + async function main(){ + const credentials = new DefaultAzureCredential(); + const client = new TargetManagementClient(credentials,subscriptionId); // must same as dependencies + for await (const item of client.operations.list()){ // you can test that you need test operation + console.log(item) + } + } + main().catch(err => { + console.log(err); }); ``` A few points, you need to pay attention here: - In the example, we are using msRestNodeAuth.interactiveLogin, you can also try other way such as Service Principal + In the example, we are using DefaultAzureCredential, you can also try other way such as InteractiveBrowserCredential ``` - const credentials = await msRestNodeAuth.loginWithServicePrincipalSecret(clientID, clientSecret, tenantID); + const credentials = new DefaultAzureCredential();; ``` In the example, we only add client.operations.list(), you may change them into other resources CURD function per your need. for example: From 8b23948544bf3a6bfde46b30212a4be019bc1387 Mon Sep 17 00:00:00 2001 From: Qiaoqiao Zhang <55688292+qiaozha@users.noreply.github.com> Date: Fri, 11 Mar 2022 09:35:20 +0800 Subject: [PATCH 2/3] Update documentation/how-to-use.md --- documentation/how-to-use.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/how-to-use.md b/documentation/how-to-use.md index 31e102effe68..602e657c46ea 100644 --- a/documentation/how-to-use.md +++ b/documentation/how-to-use.md @@ -49,7 +49,7 @@ In this document, we will give a brief introduction on how to use the JavaScript }); ``` A few points, you need to pay attention here: - In the example, we are using DefaultAzureCredential, you can also try other way such as InteractiveBrowserCredential + In the example, we are using DefaultAzureCredential, you can also try other way such as Service Principal ``` const credentials = new DefaultAzureCredential();; ``` From 1da6c6521cf741a0fb9c36c70cc8d2f5aa766002 Mon Sep 17 00:00:00 2001 From: Qiaoqiao Zhang <55688292+qiaozha@users.noreply.github.com> Date: Fri, 11 Mar 2022 09:35:41 +0800 Subject: [PATCH 3/3] Apply suggestions from code review --- documentation/how-to-use.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/how-to-use.md b/documentation/how-to-use.md index 602e657c46ea..8e11e390f4b7 100644 --- a/documentation/how-to-use.md +++ b/documentation/how-to-use.md @@ -33,7 +33,7 @@ In this document, we will give a brief introduction on how to use the JavaScript 1. Create a ts file (free name and copy follow code into this file) eg: test_1.ts eg: ``` - const DefaultAzureCredential = require("@azure/identity"); + const { DefaultAzureCredential } = require("@azure/identity"); const { TargetManagementClient } = require("@azure/arm-target"); // must same as dependencies const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; @@ -51,7 +51,7 @@ In this document, we will give a brief introduction on how to use the JavaScript A few points, you need to pay attention here: In the example, we are using DefaultAzureCredential, you can also try other way such as Service Principal ``` - const credentials = new DefaultAzureCredential();; + const credentials = new ClientSecretCredential(tenantId, clientId, clientSecret); ``` In the example, we only add client.operations.list(), you may change them into other resources CURD function per your need. for example: