Skip to content

Commit 24c4d46

Browse files
authored
bugfix (Azure#16329)
1 parent 18c9ac9 commit 24c4d46

File tree

8 files changed

+169
-121
lines changed

8 files changed

+169
-121
lines changed

sdk/reservations/arm-reservations/README.md

Lines changed: 65 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,107 @@
11
## Azure AzureReservationAPI SDK for JavaScript
22

3-
This package contains an isomorphic SDK for AzureReservationAPI.
3+
This package contains an isomorphic SDK (runs both in Node.js and in browsers) for AzureReservationAPI.
44

55
### Currently supported environments
66

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.
99

10-
### How to Install
10+
### Prerequisites
1111

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-reservations` 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:
1221
```bash
13-
npm install @azure/arm-reservations
22+
npm install --save @azure/arm-reservations @azure/identity
1423
```
1524

25+
> **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.
26+
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.
27+
1628
### How to use
1729

18-
#### nodejs - Authentication, client creation and get quota as an example written in TypeScript.
30+
- If you are writing a client side browser application,
31+
- 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.
32+
- 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.
33+
- If you are writing a server side application,
34+
- [Select a credential from `@azure/identity` based on the authentication method of your choice](https://aka.ms/azsdk/js/identity/examples)
35+
- Complete the set up steps required by the credential if any.
36+
- Use the credential you picked in the place of `DefaultAzureCredential` in the Node.js sample below.
1937

20-
##### Install @azure/ms-rest-nodeauth
38+
In the below samples, we pass the credential and the Azure subscription id to instantiate the client.
39+
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.
2140

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-
```
41+
#### nodejs - Authentication, client creation, and get quota as an example written in JavaScript.
2642

2743
##### Sample code
2844

2945
```javascript
46+
const { DefaultAzureCredential } = require("@azure/identity");
3047
const { AzureReservationAPI } = require("@azure/arm-reservations");
31-
const { interactiveLogin } = require("@azure/ms-rest-nodeauth");
32-
33-
interactiveLogin().then((creds) => {
34-
const client = new AzureReservationAPI(creds);
35-
const subscriptionId = "testsubscriptionId";
36-
const providerId = "testproviderId";
37-
const location = "westus";
38-
const resourceName = "testresourceName";
39-
client.quota.get(subscriptionId, providerId, location, resourceName).then((result) => {
40-
console.log("The result is:");
41-
console.log(result);
42-
});
48+
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
49+
50+
// Use `DefaultAzureCredential` or any other credential of your choice based on https://aka.ms/azsdk/js/identity/examples
51+
// Please note that you can also use credentials from the `@azure/ms-rest-nodeauth` package instead.
52+
const creds = new DefaultAzureCredential();
53+
const client = new AzureReservationAPI(creds, subscriptionId);
54+
const testSubscriptionId = "testsubscriptionId";
55+
const providerId = "testproviderId";
56+
const location = "westus";
57+
const resourceName = "testresourceName";
58+
client.quota.get(testSubscriptionId, providerId, location, resourceName).then((result) => {
59+
console.log("The result is:");
60+
console.log(result);
4361
}).catch((err) => {
62+
console.log("An error occurred:");
4463
console.error(err);
4564
});
4665
```
4766

48-
#### browser - Authentication, client creation and get quota as an example written in JavaScript.
67+
#### browser - Authentication, client creation, and get quota as an example written in JavaScript.
4968

50-
##### Install @azure/ms-rest-browserauth
51-
52-
```bash
53-
npm install @azure/ms-rest-browserauth
54-
```
69+
In browser applications, we recommend using the `InteractiveBrowserCredential` that interactively authenticates using the default system browser.
70+
- 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.
71+
- Note down the client Id from the previous step and use it in the browser sample below.
5572

5673
##### Sample code
5774

58-
See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.
59-
6075
- index.html
76+
6177
```html
6278
<!DOCTYPE html>
6379
<html lang="en">
6480
<head>
6581
<title>@azure/arm-reservations sample</title>
66-
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
6782
<script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script>
68-
<script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
83+
<script src="node_modules/@azure/identity/dist/index.js"></script>
6984
<script src="node_modules/@azure/arm-reservations/dist/arm-reservations.js"></script>
7085
<script type="text/javascript">
71-
const authManager = new msAuth.AuthManager({
86+
const subscriptionId = "<Subscription_Id>";
87+
// Create credentials using the `@azure/identity` package.
88+
// Please note that you can also use credentials from the `@azure/ms-rest-browserauth` package instead.
89+
const credential = new InteractiveBrowserCredential(
90+
{
7291
clientId: "<client id for your Azure AD app>",
73-
tenant: "<optional tenant for your organization>"
92+
tenantId: "<optional tenant for your organization>"
7493
});
75-
authManager.finalizeLogin().then((res) => {
76-
if (!res.isLoggedIn) {
77-
// may cause redirects
78-
authManager.login();
79-
}
80-
const client = new Azure.ArmReservations.AzureReservationAPI(res.creds);
81-
const subscriptionId = "testsubscriptionId";
82-
const providerId = "testproviderId";
83-
const location = "westus";
84-
const resourceName = "testresourceName";
85-
client.quota.get(subscriptionId, providerId, location, resourceName).then((result) => {
86-
console.log("The result is:");
87-
console.log(result);
88-
}).catch((err) => {
89-
console.log("An error occurred:");
90-
console.error(err);
91-
});
94+
const client = new Azure.ArmReservations.AzureReservationAPI(creds, subscriptionId);
95+
const testSubscriptionId = "testsubscriptionId";
96+
const providerId = "testproviderId";
97+
const location = "westus";
98+
const resourceName = "testresourceName";
99+
client.quota.get(testSubscriptionId, providerId, location, resourceName).then((result) => {
100+
console.log("The result is:");
101+
console.log(result);
102+
}).catch((err) => {
103+
console.log("An error occurred:");
104+
console.error(err);
92105
});
93106
</script>
94107
</head>

sdk/reservations/arm-reservations/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"name": "@azure/arm-reservations",
33
"author": "Microsoft Corporation",
44
"description": "AzureReservationAPI Library with typescript type definitions for node.js and browser.",
5-
"version": "6.0.0",
5+
"version": "6.1.0",
66
"dependencies": {
7-
"@azure/ms-rest-azure-js": "^2.0.1",
8-
"@azure/ms-rest-js": "^2.0.4",
7+
"@azure/ms-rest-azure-js": "^2.1.0",
8+
"@azure/ms-rest-js": "^2.2.0",
9+
"@azure/core-auth": "^1.1.4",
910
"tslib": "^1.10.0"
1011
},
1112
"keywords": [
@@ -20,7 +21,7 @@
2021
"module": "./esm/azureReservationAPI.js",
2122
"types": "./esm/azureReservationAPI.d.ts",
2223
"devDependencies": {
23-
"typescript": "^3.5.3",
24+
"typescript": "^3.6.0",
2425
"rollup": "^1.18.0",
2526
"rollup-plugin-node-resolve": "^5.2.0",
2627
"rollup-plugin-sourcemaps": "^0.4.2",

sdk/reservations/arm-reservations/src/azureReservationAPI.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import * as msRest from "@azure/ms-rest-js";
11+
import { TokenCredential } from "@azure/core-auth";
1112
import * as Models from "./models";
1213
import * as Mappers from "./models/mappers";
1314
import * as Parameters from "./models/parameters";
@@ -27,10 +28,15 @@ class AzureReservationAPI extends AzureReservationAPIContext {
2728

2829
/**
2930
* Initializes a new instance of the AzureReservationAPI class.
30-
* @param credentials Credentials needed for the client to connect to Azure.
31+
* @param credentials Credentials needed for the client to connect to Azure. Credentials
32+
* implementing the TokenCredential interface from the @azure/identity package are recommended. For
33+
* more information about these credentials, see
34+
* {@link https://www.npmjs.com/package/@azure/identity}. Credentials implementing the
35+
* ServiceClientCredentials interface from the older packages @azure/ms-rest-nodeauth and
36+
* @azure/ms-rest-browserauth are also supported.
3137
* @param [options] The parameter options
3238
*/
33-
constructor(credentials: msRest.ServiceClientCredentials, options?: Models.AzureReservationAPIOptions) {
39+
constructor(credentials: msRest.ServiceClientCredentials | TokenCredential, options?: Models.AzureReservationAPIOptions) {
3440
super(credentials, options);
3541
this.reservation = new operations.Reservation(this);
3642
this.reservationOrder = new operations.ReservationOrder(this);

sdk/reservations/arm-reservations/src/azureReservationAPIContext.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,26 @@
99

1010
import * as Models from "./models";
1111
import * as msRest from "@azure/ms-rest-js";
12+
import { TokenCredential } from "@azure/core-auth";
1213
import * as msRestAzure from "@azure/ms-rest-azure-js";
1314

1415
const packageName = "@azure/arm-reservations";
15-
const packageVersion = "6.0.0";
16+
const packageVersion = "6.1.0";
1617

1718
export class AzureReservationAPIContext extends msRestAzure.AzureServiceClient {
18-
credentials: msRest.ServiceClientCredentials;
19+
credentials: msRest.ServiceClientCredentials | TokenCredential;
1920

2021
/**
2122
* Initializes a new instance of the AzureReservationAPI class.
22-
* @param credentials Credentials needed for the client to connect to Azure.
23+
* @param credentials Credentials needed for the client to connect to Azure. Credentials
24+
* implementing the TokenCredential interface from the @azure/identity package are recommended. For
25+
* more information about these credentials, see
26+
* {@link https://www.npmjs.com/package/@azure/identity}. Credentials implementing the
27+
* ServiceClientCredentials interface from the older packages @azure/ms-rest-nodeauth and
28+
* @azure/ms-rest-browserauth are also supported.
2329
* @param [options] The parameter options
2430
*/
25-
constructor(credentials: msRest.ServiceClientCredentials, options?: Models.AzureReservationAPIOptions) {
31+
constructor(credentials: msRest.ServiceClientCredentials | TokenCredential, options?: Models.AzureReservationAPIOptions) {
2632
if (credentials == undefined) {
2733
throw new Error('\'credentials\' cannot be null.');
2834
}

sdk/subscription/arm-subscriptions/README.md

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,101 @@
11
## Azure SubscriptionClient SDK for JavaScript
22

3-
This package contains an isomorphic SDK for SubscriptionClient.
3+
This package contains an isomorphic SDK (runs both in Node.js and in browsers) for SubscriptionClient.
44

55
### Currently supported environments
66

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.
99

10-
### How to Install
10+
### Prerequisites
1111

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-subscriptions` 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:
1221
```bash
13-
npm install @azure/arm-subscriptions
22+
npm install --save @azure/arm-subscriptions @azure/identity
1423
```
1524

25+
> **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.
26+
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.
27+
1628
### How to use
1729

18-
#### nodejs - Authentication, client creation and listLocations subscriptions as an example written in TypeScript.
30+
- If you are writing a client side browser application,
31+
- 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.
32+
- 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.
33+
- If you are writing a server side application,
34+
- [Select a credential from `@azure/identity` based on the authentication method of your choice](https://aka.ms/azsdk/js/identity/examples)
35+
- Complete the set up steps required by the credential if any.
36+
- Use the credential you picked in the place of `DefaultAzureCredential` in the Node.js sample below.
1937

20-
##### Install @azure/ms-rest-nodeauth
38+
In the below samples, we pass the credential and the Azure subscription id to instantiate the client.
39+
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.
2140

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-
```
41+
#### nodejs - Authentication, client creation, and listLocations subscriptions as an example written in JavaScript.
2642

2743
##### Sample code
2844

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 { SubscriptionClient, SubscriptionModels, SubscriptionMappers } from "@azure/arm-subscriptions";
45+
```javascript
46+
const { DefaultAzureCredential } = require("@azure/identity");
47+
const { SubscriptionClient } = require("@azure/arm-subscriptions");
3448
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
3549

36-
msRestNodeAuth.interactiveLogin().then((creds) => {
37-
const client = new SubscriptionClient(creds, subscriptionId);
38-
const subscriptionId = "testsubscriptionId";
39-
client.subscriptions.listLocations(subscriptionId).then((result) => {
40-
console.log("The result is:");
41-
console.log(result);
42-
});
50+
// Use `DefaultAzureCredential` or any other credential of your choice based on https://aka.ms/azsdk/js/identity/examples
51+
// Please note that you can also use credentials from the `@azure/ms-rest-nodeauth` package instead.
52+
const creds = new DefaultAzureCredential();
53+
const client = new SubscriptionClient(creds, subscriptionId);
54+
const testSubscriptionId = "testsubscriptionId";
55+
client.subscriptions.listLocations(testSubscriptionId).then((result) => {
56+
console.log("The result is:");
57+
console.log(result);
4358
}).catch((err) => {
59+
console.log("An error occurred:");
4460
console.error(err);
4561
});
4662
```
4763

48-
#### browser - Authentication, client creation and listLocations subscriptions as an example written in JavaScript.
64+
#### browser - Authentication, client creation, and listLocations subscriptions as an example written in JavaScript.
4965

50-
##### Install @azure/ms-rest-browserauth
51-
52-
```bash
53-
npm install @azure/ms-rest-browserauth
54-
```
66+
In browser applications, we recommend using the `InteractiveBrowserCredential` that interactively authenticates using the default system browser.
67+
- 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.
68+
- Note down the client Id from the previous step and use it in the browser sample below.
5569

5670
##### Sample code
5771

58-
See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.
59-
6072
- index.html
73+
6174
```html
6275
<!DOCTYPE html>
6376
<html lang="en">
6477
<head>
6578
<title>@azure/arm-subscriptions sample</title>
66-
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
6779
<script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script>
68-
<script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
80+
<script src="node_modules/@azure/identity/dist/index.js"></script>
6981
<script src="node_modules/@azure/arm-subscriptions/dist/arm-subscriptions.js"></script>
7082
<script type="text/javascript">
7183
const subscriptionId = "<Subscription_Id>";
72-
const authManager = new msAuth.AuthManager({
84+
// Create credentials using the `@azure/identity` package.
85+
// Please note that you can also use credentials from the `@azure/ms-rest-browserauth` package instead.
86+
const credential = new InteractiveBrowserCredential(
87+
{
7388
clientId: "<client id for your Azure AD app>",
74-
tenant: "<optional tenant for your organization>"
89+
tenantId: "<optional tenant for your organization>"
7590
});
76-
authManager.finalizeLogin().then((res) => {
77-
if (!res.isLoggedIn) {
78-
// may cause redirects
79-
authManager.login();
80-
}
81-
const client = new Azure.ArmSubscriptions.SubscriptionClient(res.creds, subscriptionId);
82-
const subscriptionId = "testsubscriptionId";
83-
client.subscriptions.listLocations(subscriptionId).then((result) => {
84-
console.log("The result is:");
85-
console.log(result);
86-
}).catch((err) => {
87-
console.log("An error occurred:");
88-
console.error(err);
89-
});
91+
const client = new Azure.ArmSubscriptions.SubscriptionClient(creds, subscriptionId);
92+
const testSubscriptionId = "testsubscriptionId";
93+
client.subscriptions.listLocations(testSubscriptionId).then((result) => {
94+
console.log("The result is:");
95+
console.log(result);
96+
}).catch((err) => {
97+
console.log("An error occurred:");
98+
console.error(err);
9099
});
91100
</script>
92101
</head>

0 commit comments

Comments
 (0)