|
1 | 1 | ## Azure DataFactoryManagementClient SDK for JavaScript |
2 | 2 |
|
3 | | -This package contains an isomorphic SDK for DataFactoryManagementClient. |
| 3 | +This package contains an isomorphic SDK (runs both in node.js and in browsers) for DataFactoryManagementClient. |
4 | 4 |
|
5 | 5 | ### Currently supported environments |
6 | 6 |
|
7 | | -- Node.js version 6.x.x or higher |
8 | | -- Browser JavaScript |
| 7 | +- [LTS versions of Node.js](https://nodejs.org/about/releases/) |
| 8 | +- Latest versions of Safari, Chrome, Edge, and Firefox. |
9 | 9 |
|
10 | | -### How to Install |
| 10 | +### Prerequisites |
| 11 | + |
| 12 | +You must have an [Azure subscription](https://azure.microsoft.com/free/). |
| 13 | + |
| 14 | +### How to install |
| 15 | + |
| 16 | +To use this SDK in your project, you will need to install two packages. |
| 17 | + |
| 18 | +- `@azure/arm-datafactory` that contains the client. |
| 19 | +- `@azure/identity` that provides different mechanisms for the client to authenticate your requests using Azure Active Directory. |
| 20 | + |
| 21 | +Install both packages using the below command: |
11 | 22 |
|
12 | 23 | ```bash |
13 | | -npm install @azure/arm-datafactory |
| 24 | +npm install --save @azure/arm-datafactory @azure/identity |
14 | 25 | ``` |
15 | 26 |
|
| 27 | +> **Note**: You may have used either `@azure/ms-rest-nodeauth` or `@azure/ms-rest-browserauth` in the past. These packages are in maintenance mode receiving critical bug fixes, but no new features. |
| 28 | +> If you are on a [Node.js that has LTS status](https://nodejs.org/about/releases/), or are writing a client side browser application, we strongly encourage you to upgrade to `@azure/identity` which uses the latest versions of Azure Active Directory and MSAL APIs and provides more authentication options. |
| 29 | +
|
16 | 30 | ### How to use |
17 | 31 |
|
18 | | -#### nodejs - client creation and list operations as an example written in TypeScript. |
| 32 | +- If you are writing a client side browser application, |
| 33 | + - Follow the instructions in the section on Authenticating client side browser applications in [Azure Identity examples](https://aka.ms/azsdk/js/identity/examples) to register your application in the Microsoft identity platform and set the right permissions. |
| 34 | + - Copy the client ID and tenant ID from the Overview section of your app registration in Azure portal and use it in the browser sample below. |
| 35 | +- If you are writing a server side application, |
| 36 | + - [Select a credential from `@azure/identity` based on the authentication method of your choice](https://aka.ms/azsdk/js/identity/examples) |
| 37 | + - Complete the set up steps required by the credential if any. |
| 38 | + - Use the credential you picked in the place of `DefaultAzureCredential` in the Node.js sample below. |
19 | 39 |
|
20 | | -##### Install @azure/ms-rest-nodeauth |
| 40 | +In the below samples, we pass the credential and the Azure subscription id to instantiate the client. |
| 41 | +Once the client is created, explore the operations on it either in your favorite editor or in our [API reference documentation](https://docs.microsoft.com/javascript/api) to get started. |
21 | 42 |
|
22 | | -- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`. |
23 | | -```bash |
24 | | -npm install @azure/ms-rest-nodeauth@"^3.0.0" |
25 | | -``` |
| 43 | +#### nodejs - Authentication, client creation, and list operations as an example written in JavaScript. |
26 | 44 |
|
27 | 45 | ##### Sample code |
28 | 46 |
|
29 | | -While the below sample uses the interactive login, other authentication options can be found in the [README.md file of @azure/ms-rest-nodeauth](https://www.npmjs.com/package/@azure/ms-rest-nodeauth) package |
30 | | -```typescript |
31 | | -const msRestNodeAuth = require("@azure/ms-rest-nodeauth"); |
| 47 | +```javascript |
| 48 | +const { DefaultAzureCredential } = require("@azure/identity"); |
32 | 49 | const { DataFactoryManagementClient } = require("@azure/arm-datafactory"); |
33 | 50 | const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; |
34 | 51 |
|
35 | | -msRestNodeAuth.interactiveLogin().then((creds) => { |
36 | | - const client = new DataFactoryManagementClient(creds, subscriptionId); |
37 | | - client.operations.list().then((result) => { |
| 52 | +// Use `DefaultAzureCredential` or any other credential of your choice based on https://aka.ms/azsdk/js/identity/examples |
| 53 | +// Please note that you can also use credentials from the `@azure/ms-rest-nodeauth` package instead. |
| 54 | +const creds = new DefaultAzureCredential(); |
| 55 | +const client = new DataFactoryManagementClient(creds, subscriptionId); |
| 56 | +client.operations |
| 57 | + .list() |
| 58 | + .then((result) => { |
38 | 59 | console.log("The result is:"); |
39 | 60 | console.log(result); |
| 61 | + }) |
| 62 | + .catch((err) => { |
| 63 | + console.log("An error occurred:"); |
| 64 | + console.error(err); |
40 | 65 | }); |
41 | | -}).catch((err) => { |
42 | | - console.error(err); |
43 | | -}); |
44 | 66 | ``` |
45 | 67 |
|
46 | | -#### browser - Authentication, client creation and list operations as an example written in JavaScript. |
| 68 | +#### browser - Authentication, client creation, and list operations as an example written in JavaScript. |
47 | 69 |
|
48 | | -##### Install @azure/ms-rest-browserauth |
| 70 | +In browser applications, we recommend using the `InteractiveBrowserCredential` that interactively authenticates using the default system browser. |
49 | 71 |
|
50 | | -```bash |
51 | | -npm install @azure/ms-rest-browserauth |
52 | | -``` |
| 72 | +- See [Single-page application: App registration guide](https://docs.microsoft.com/azure/active-directory/develop/scenario-spa-app-registration) to configure your app registration for the browser. |
| 73 | +- Note down the client Id from the previous step and use it in the browser sample below. |
53 | 74 |
|
54 | 75 | ##### Sample code |
55 | 76 |
|
56 | | -See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. |
57 | | - |
58 | 77 | - index.html |
| 78 | + |
59 | 79 | ```html |
60 | 80 | <!DOCTYPE html> |
61 | 81 | <html lang="en"> |
62 | 82 | <head> |
63 | 83 | <title>@azure/arm-datafactory sample</title> |
64 | | - <script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script> |
65 | 84 | <script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script> |
66 | | - <script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script> |
| 85 | + <script src="node_modules/@azure/identity/dist/index.js"></script> |
67 | 86 | <script src="node_modules/@azure/arm-datafactory/dist/arm-datafactory.js"></script> |
68 | 87 | <script type="text/javascript"> |
69 | 88 | const subscriptionId = "<Subscription_Id>"; |
70 | | - const authManager = new msAuth.AuthManager({ |
| 89 | + // Create credentials using the `@azure/identity` package. |
| 90 | + // Please note that you can also use credentials from the `@azure/ms-rest-browserauth` package instead. |
| 91 | + const credential = new InteractiveBrowserCredential({ |
71 | 92 | clientId: "<client id for your Azure AD app>", |
72 | 93 | tenant: "<optional tenant for your organization>" |
73 | 94 | }); |
74 | | - authManager.finalizeLogin().then((res) => { |
75 | | - if (!res.isLoggedIn) { |
76 | | - // may cause redirects |
77 | | - authManager.login(); |
78 | | - } |
79 | | - const client = new Azure.ArmDatafactory.DataFactoryManagementClient(res.creds, subscriptionId); |
80 | | - client.operations.list().then((result) => { |
| 95 | + const client = new Azure.ArmDatafactory.DataFactoryManagementClient(creds, subscriptionId); |
| 96 | + client.operations |
| 97 | + .list() |
| 98 | + .then((result) => { |
81 | 99 | console.log("The result is:"); |
82 | 100 | console.log(result); |
83 | | - }).catch((err) => { |
| 101 | + }) |
| 102 | + .catch((err) => { |
84 | 103 | console.log("An error occurred:"); |
85 | 104 | console.error(err); |
86 | 105 | }); |
87 | | - }); |
88 | 106 | </script> |
89 | 107 | </head> |
90 | 108 | <body></body> |
|
0 commit comments