|
1 | 1 | ## Azure RecoveryServicesBackupClient SDK for JavaScript |
2 | 2 |
|
3 | | -This package contains an isomorphic SDK for RecoveryServicesBackupClient. |
| 3 | +This package contains an isomorphic SDK (runs both in Node.js and in browsers) for RecoveryServicesBackupClient. |
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-recoveryservicesbackup` 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-recoveryservicesbackup |
| 24 | +npm install --save @azure/arm-recoveryservicesbackup @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 - Authentication, client creation and get privateEndpointConnection 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 get backupResourceVaultConfigs as an example written in JavaScript. |
26 | 44 |
|
27 | 45 | ##### Sample code |
28 | 46 |
|
29 | | -```typescript |
30 | | -import * as msRest from "@azure/ms-rest-js"; |
31 | | -import * as msRestAzure from "@azure/ms-rest-azure-js"; |
32 | | -import * as msRestNodeAuth from "@azure/ms-rest-nodeauth"; |
33 | | -import { RecoveryServicesBackupClient, RecoveryServicesBackupModels, RecoveryServicesBackupMappers } from "@azure/arm-recoveryservicesbackup"; |
| 47 | +```javascript |
| 48 | +const { DefaultAzureCredential } = require("@azure/identity"); |
| 49 | +const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup"); |
34 | 50 | const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; |
35 | 51 |
|
36 | | -msRestNodeAuth.interactiveLogin().then((creds) => { |
37 | | - const client = new RecoveryServicesBackupClient(creds, subscriptionId); |
38 | | - const vaultName = "testvaultName"; |
39 | | - const resourceGroupName = "testresourceGroupName"; |
40 | | - const privateEndpointConnectionName = "testprivateEndpointConnectionName"; |
41 | | - client.privateEndpointConnection.get(vaultName, resourceGroupName, privateEndpointConnectionName).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 RecoveryServicesBackupClient(creds, subscriptionId); |
| 56 | +const vaultName = "testvaultName"; |
| 57 | +const resourceGroupName = "testresourceGroupName"; |
| 58 | +client.backupResourceVaultConfigs |
| 59 | + .get(vaultName, resourceGroupName) |
| 60 | + .then((result) => { |
42 | 61 | console.log("The result is:"); |
43 | 62 | console.log(result); |
| 63 | + }) |
| 64 | + .catch((err) => { |
| 65 | + console.log("An error occurred:"); |
| 66 | + console.error(err); |
44 | 67 | }); |
45 | | -}).catch((err) => { |
46 | | - console.error(err); |
47 | | -}); |
48 | 68 | ``` |
49 | 69 |
|
50 | | -#### browser - Authentication, client creation and get privateEndpointConnection as an example written in JavaScript. |
| 70 | +#### browser - Authentication, client creation, and get backupResourceVaultConfigs as an example written in JavaScript. |
51 | 71 |
|
52 | | -##### Install @azure/ms-rest-browserauth |
| 72 | +In browser applications, we recommend using the `InteractiveBrowserCredential` that interactively authenticates using the default system browser. |
53 | 73 |
|
54 | | -```bash |
55 | | -npm install @azure/ms-rest-browserauth |
56 | | -``` |
| 74 | +- 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. |
| 75 | +- Note down the client Id from the previous step and use it in the browser sample below. |
57 | 76 |
|
58 | 77 | ##### Sample code |
59 | 78 |
|
60 | | -See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. |
61 | | - |
62 | 79 | - index.html |
| 80 | + |
63 | 81 | ```html |
64 | 82 | <!DOCTYPE html> |
65 | 83 | <html lang="en"> |
66 | 84 | <head> |
67 | 85 | <title>@azure/arm-recoveryservicesbackup sample</title> |
68 | | - <script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script> |
69 | 86 | <script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script> |
70 | | - <script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script> |
| 87 | + <script src="node_modules/@azure/identity/dist/index.js"></script> |
71 | 88 | <script src="node_modules/@azure/arm-recoveryservicesbackup/dist/arm-recoveryservicesbackup.js"></script> |
72 | 89 | <script type="text/javascript"> |
73 | 90 | const subscriptionId = "<Subscription_Id>"; |
74 | | - const authManager = new msAuth.AuthManager({ |
| 91 | + // Create credentials using the `@azure/identity` package. |
| 92 | + // Please note that you can also use credentials from the `@azure/ms-rest-browserauth` package instead. |
| 93 | + const credential = new InteractiveBrowserCredential({ |
75 | 94 | clientId: "<client id for your Azure AD app>", |
76 | 95 | tenant: "<optional tenant for your organization>" |
77 | 96 | }); |
78 | | - authManager.finalizeLogin().then((res) => { |
79 | | - if (!res.isLoggedIn) { |
80 | | - // may cause redirects |
81 | | - authManager.login(); |
82 | | - } |
83 | | - const client = new Azure.ArmRecoveryservicesbackup.RecoveryServicesBackupClient(res.creds, subscriptionId); |
84 | | - const vaultName = "testvaultName"; |
85 | | - const resourceGroupName = "testresourceGroupName"; |
86 | | - const privateEndpointConnectionName = "testprivateEndpointConnectionName"; |
87 | | - client.privateEndpointConnection.get(vaultName, resourceGroupName, privateEndpointConnectionName).then((result) => { |
| 97 | + const client = new Azure.ArmRecoveryservicesbackup.RecoveryServicesBackupClient( |
| 98 | + creds, |
| 99 | + subscriptionId |
| 100 | + ); |
| 101 | + const vaultName = "testvaultName"; |
| 102 | + const resourceGroupName = "testresourceGroupName"; |
| 103 | + client.backupResourceVaultConfigs |
| 104 | + .get(vaultName, resourceGroupName) |
| 105 | + .then((result) => { |
88 | 106 | console.log("The result is:"); |
89 | 107 | console.log(result); |
90 | | - }).catch((err) => { |
| 108 | + }) |
| 109 | + .catch((err) => { |
91 | 110 | console.log("An error occurred:"); |
92 | 111 | console.error(err); |
93 | 112 | }); |
94 | | - }); |
95 | 113 | </script> |
96 | 114 | </head> |
97 | 115 | <body></body> |
|
0 commit comments