|  | 
|  | 1 | +## Azure AzureOrbital SDK for JavaScript | 
|  | 2 | + | 
|  | 3 | +This package contains an isomorphic SDK (runs both in node.js and in browsers) for AzureOrbital. | 
|  | 4 | + | 
|  | 5 | +### Currently supported environments | 
|  | 6 | + | 
|  | 7 | +- [LTS versions of Node.js](https://nodejs.org/about/releases/) | 
|  | 8 | +- Latest versions of Safari, Chrome, Edge and Firefox. | 
|  | 9 | + | 
|  | 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 | +- `@azure/arm-orbital` that contains the client. | 
|  | 18 | +- `@azure/identity` that provides different mechanisms for the client to authenticate your requests using Azure Active Directory. | 
|  | 19 | + | 
|  | 20 | +Install both packages using the below command: | 
|  | 21 | +```bash | 
|  | 22 | +npm install --save @azure/arm-orbital @azure/identity | 
|  | 23 | +``` | 
|  | 24 | +> **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. | 
|  | 25 | +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. | 
|  | 26 | + | 
|  | 27 | +### How to use | 
|  | 28 | + | 
|  | 29 | +- If you are writing a client side browser application, | 
|  | 30 | +  - 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. | 
|  | 31 | +  - 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. | 
|  | 32 | +- If you are writing a server side application, | 
|  | 33 | +  - [Select a credential from `@azure/identity` based on the authentication method of your choice](https://aka.ms/azsdk/js/identity/examples) | 
|  | 34 | +  - Complete the set up steps required by the credential if any. | 
|  | 35 | +  - Use the credential you picked in the place of `DefaultAzureCredential` in the Node.js sample below. | 
|  | 36 | + | 
|  | 37 | +In the below samples, we pass the credential and the Azure subscription id to instantiate the client. | 
|  | 38 | +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. | 
|  | 39 | +#### nodejs - Authentication, client creation, and list operations as an example written in JavaScript. | 
|  | 40 | + | 
|  | 41 | +##### Sample code | 
|  | 42 | + | 
|  | 43 | +```javascript | 
|  | 44 | +const { DefaultAzureCredential } = require("@azure/identity"); | 
|  | 45 | +const { AzureOrbital } = require("@azure/arm-orbital"); | 
|  | 46 | +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; | 
|  | 47 | + | 
|  | 48 | +// Use `DefaultAzureCredential` or any other credential of your choice based on https://aka.ms/azsdk/js/identity/examples | 
|  | 49 | +// Please note that you can also use credentials from the `@azure/ms-rest-nodeauth` package instead. | 
|  | 50 | +const creds = new DefaultAzureCredential(); | 
|  | 51 | +const client = new AzureOrbital(creds, subscriptionId); | 
|  | 52 | +client.operations.list().then((result) => { | 
|  | 53 | +  console.log("The result is:"); | 
|  | 54 | +  console.log(result); | 
|  | 55 | +}).catch((err) => { | 
|  | 56 | +  console.log("An error occurred:"); | 
|  | 57 | +  console.error(err); | 
|  | 58 | +}); | 
|  | 59 | +``` | 
|  | 60 | + | 
|  | 61 | +#### browser - Authentication, client creation, and list operations as an example written in JavaScript. | 
|  | 62 | + | 
|  | 63 | +In browser applications, we recommend using the `InteractiveBrowserCredential` that interactively authenticates using the default system browser. | 
|  | 64 | +  - 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. | 
|  | 65 | +  - Note down the client Id from the previous step and use it in the browser sample below. | 
|  | 66 | + | 
|  | 67 | +##### Sample code | 
|  | 68 | + | 
|  | 69 | +- index.html | 
|  | 70 | + | 
|  | 71 | +```html | 
|  | 72 | +<!DOCTYPE html> | 
|  | 73 | +<html lang="en"> | 
|  | 74 | +  <head> | 
|  | 75 | +    <title>@azure/arm-orbital sample</title> | 
|  | 76 | +    <script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script> | 
|  | 77 | +    <script src="node_modules/@azure/identity/dist/index.js"></script> | 
|  | 78 | +    <script src="node_modules/@azure/arm-orbital/dist/arm-orbital.js"></script> | 
|  | 79 | +    <script type="text/javascript"> | 
|  | 80 | +      const subscriptionId = "<Subscription_Id>"; | 
|  | 81 | +      // Create credentials using the `@azure/identity` package. | 
|  | 82 | +      // Please note that you can also use credentials from the `@azure/ms-rest-browserauth` package instead. | 
|  | 83 | +      const credential = new InteractiveBrowserCredential( | 
|  | 84 | +      { | 
|  | 85 | +        clientId: "<client id for your Azure AD app>", | 
|  | 86 | +        tenant: "<optional tenant for your organization>" | 
|  | 87 | +      }); | 
|  | 88 | +      const client = new Azure.ArmOrbital.AzureOrbital(creds, subscriptionId); | 
|  | 89 | +      client.operations.list().then((result) => { | 
|  | 90 | +        console.log("The result is:"); | 
|  | 91 | +        console.log(result); | 
|  | 92 | +      }).catch((err) => { | 
|  | 93 | +        console.log("An error occurred:"); | 
|  | 94 | +        console.error(err); | 
|  | 95 | +      }); | 
|  | 96 | +    </script> | 
|  | 97 | +  </head> | 
|  | 98 | +  <body></body> | 
|  | 99 | +</html> | 
|  | 100 | +``` | 
|  | 101 | + | 
|  | 102 | +## Related projects | 
|  | 103 | + | 
|  | 104 | +- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) | 
|  | 105 | + | 
|  | 106 | + | 
0 commit comments