Skip to content

Commit 37d1df4

Browse files
authored
arm-support-identity (Azure#15838)
1 parent d023204 commit 37d1df4

File tree

196 files changed

+4041
-2949
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+4041
-2949
lines changed

sdk/advisor/arm-advisor/README.md

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

3-
This package contains an isomorphic SDK for AdvisorManagementClient.
3+
This package contains an isomorphic SDK (runs both in Node.js and in browsers) for AdvisorManagementClient.
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-advisor` 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-advisor
22+
npm install --save @azure/arm-advisor @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 recommendationMetadata 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 recommendationMetadata 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 { AdvisorManagementClient, AdvisorManagementModels, AdvisorManagementMappers } from "@azure/arm-advisor";
45+
```javascript
46+
const { DefaultAzureCredential } = require("@azure/identity");
47+
const { AdvisorManagementClient } = require("@azure/arm-advisor");
3448
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
3549

36-
msRestNodeAuth.interactiveLogin().then((creds) => {
37-
const client = new AdvisorManagementClient(creds, subscriptionId);
38-
const name = "testname";
39-
client.recommendationMetadata.get(name).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 AdvisorManagementClient(creds, subscriptionId);
54+
const name = "testname";
55+
client.recommendationMetadata.get(name).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 get recommendationMetadata as an example written in JavaScript.
64+
#### browser - Authentication, client creation, and get recommendationMetadata 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-advisor 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-advisor/dist/arm-advisor.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.ArmAdvisor.AdvisorManagementClient(res.creds, subscriptionId);
82-
const name = "testname";
83-
client.recommendationMetadata.get(name).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.ArmAdvisor.AdvisorManagementClient(creds, subscriptionId);
92+
const name = "testname";
93+
client.recommendationMetadata.get(name).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>

sdk/advisor/arm-advisor/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"name": "@azure/arm-advisor",
33
"author": "Microsoft Corporation",
44
"description": "AdvisorManagementClient Library with typescript type definitions for node.js and browser.",
5-
"version": "2.0.0",
5+
"version": "2.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/advisorManagementClient.js",
2122
"types": "./esm/advisorManagementClient.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/advisor/arm-advisor/src/advisorManagementClient.ts

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

1111
import * as msRest from "@azure/ms-rest-js";
12+
import { TokenCredential } from "@azure/core-auth";
1213
import * as Models from "./models";
1314
import * as Mappers from "./models/mappers";
1415
import * as operations from "./operations";
@@ -25,11 +26,16 @@ class AdvisorManagementClient extends AdvisorManagementClientContext {
2526

2627
/**
2728
* Initializes a new instance of the AdvisorManagementClient class.
28-
* @param credentials Credentials needed for the client to connect to Azure.
29+
* @param credentials Credentials needed for the client to connect to Azure. Credentials
30+
* implementing the TokenCredential interface from the @azure/identity package are recommended. For
31+
* more information about these credentials, see
32+
* {@link https://www.npmjs.com/package/@azure/identity}. Credentials implementing the
33+
* ServiceClientCredentials interface from the older packages @azure/ms-rest-nodeauth and
34+
* @azure/ms-rest-browserauth are also supported.
2935
* @param subscriptionId The Azure subscription ID.
3036
* @param [options] The parameter options
3137
*/
32-
constructor(credentials: msRest.ServiceClientCredentials, subscriptionId: string, options?: Models.AdvisorManagementClientOptions) {
38+
constructor(credentials: msRest.ServiceClientCredentials | TokenCredential, subscriptionId: string, options?: Models.AdvisorManagementClientOptions) {
3339
super(credentials, subscriptionId, options);
3440
this.recommendationMetadata = new operations.RecommendationMetadata(this);
3541
this.configurations = new operations.Configurations(this);

sdk/advisor/arm-advisor/src/advisorManagementClientContext.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,29 @@
1010

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

1516
const packageName = "@azure/arm-advisor";
16-
const packageVersion = "2.0.0";
17+
const packageVersion = "2.1.0";
1718

1819
export class AdvisorManagementClientContext extends msRestAzure.AzureServiceClient {
19-
credentials: msRest.ServiceClientCredentials;
20+
credentials: msRest.ServiceClientCredentials | TokenCredential;
2021
subscriptionId: string;
2122
apiVersion?: string;
2223

2324
/**
2425
* Initializes a new instance of the AdvisorManagementClient class.
25-
* @param credentials Credentials needed for the client to connect to Azure.
26+
* @param credentials Credentials needed for the client to connect to Azure. Credentials
27+
* implementing the TokenCredential interface from the @azure/identity package are recommended. For
28+
* more information about these credentials, see
29+
* {@link https://www.npmjs.com/package/@azure/identity}. Credentials implementing the
30+
* ServiceClientCredentials interface from the older packages @azure/ms-rest-nodeauth and
31+
* @azure/ms-rest-browserauth are also supported.
2632
* @param subscriptionId The Azure subscription ID.
2733
* @param [options] The parameter options
2834
*/
29-
constructor(credentials: msRest.ServiceClientCredentials, subscriptionId: string, options?: Models.AdvisorManagementClientOptions) {
35+
constructor(credentials: msRest.ServiceClientCredentials | TokenCredential, subscriptionId: string, options?: Models.AdvisorManagementClientOptions) {
3036
if (credentials == undefined) {
3137
throw new Error('\'credentials\' cannot be null.');
3238
}
Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,103 @@
11
## Azure AnalysisServicesManagementClient SDK for JavaScript
22

3-
This package contains an isomorphic SDK for AnalysisServicesManagementClient.
3+
This package contains an isomorphic SDK (runs both in Node.js and in browsers) for AnalysisServicesManagementClient.
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-
```
13-
npm install @azure/arm-analysisservices
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-analysisservices` 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-analysisservices @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 getDetails servers 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-
```
23-
npm install @azure/ms-rest-nodeauth
24-
```
41+
#### nodejs - Authentication, client creation, and getDetails servers as an example written in JavaScript.
2542

2643
##### Sample code
2744

28-
```ts
29-
import * as msRest from "@azure/ms-rest-js";
30-
import * as msRestAzure from "@azure/ms-rest-azure-js";
31-
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
32-
import { AnalysisServicesManagementClient, AnalysisServicesManagementModels, AnalysisServicesManagementMappers } from "@azure/arm-analysisservices";
45+
```javascript
46+
const { DefaultAzureCredential } = require("@azure/identity");
47+
const { AnalysisServicesManagementClient } = require("@azure/arm-analysisservices");
3348
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
3449

35-
msRestNodeAuth.interactiveLogin().then((creds) => {
36-
const client = new AnalysisServicesManagementClient(creds, subscriptionId);
37-
const resourceGroupName = "testresourceGroupName";
38-
const serverName = "testserverName";
39-
client.servers.getDetails(resourceGroupName, serverName).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 AnalysisServicesManagementClient(creds, subscriptionId);
54+
const resourceGroupName = "testresourceGroupName";
55+
const serverName = "testserverName";
56+
client.servers.getDetails(resourceGroupName, serverName).then((result) => {
57+
console.log("The result is:");
58+
console.log(result);
4359
}).catch((err) => {
60+
console.log("An error occurred:");
4461
console.error(err);
4562
});
4663
```
4764

48-
#### browser - Authentication, client creation and getDetails servers as an example written in JavaScript.
65+
#### browser - Authentication, client creation, and getDetails servers as an example written in JavaScript.
4966

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

5671
##### Sample code
5772

58-
See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.
59-
6073
- index.html
74+
6175
```html
6276
<!DOCTYPE html>
6377
<html lang="en">
6478
<head>
6579
<title>@azure/arm-analysisservices sample</title>
66-
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
6780
<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>
81+
<script src="node_modules/@azure/identity/dist/index.js"></script>
6982
<script src="node_modules/@azure/arm-analysisservices/dist/arm-analysisservices.js"></script>
7083
<script type="text/javascript">
7184
const subscriptionId = "<Subscription_Id>";
72-
const authManager = new msAuth.AuthManager({
85+
// Create credentials using the `@azure/identity` package.
86+
// Please note that you can also use credentials from the `@azure/ms-rest-browserauth` package instead.
87+
const credential = new InteractiveBrowserCredential(
88+
{
7389
clientId: "<client id for your Azure AD app>",
74-
tenant: "<optional tenant for your organization>"
90+
tenantId: "<optional tenant for your organization>"
7591
});
76-
authManager.finalizeLogin().then((res) => {
77-
if (!res.isLoggedIn) {
78-
// may cause redirects
79-
authManager.login();
80-
}
81-
const client = new Azure.ArmAnalysisservices.AnalysisServicesManagementClient(res.creds, subscriptionId);
82-
const resourceGroupName = "testresourceGroupName";
83-
const serverName = "testserverName";
84-
client.servers.getDetails(resourceGroupName, serverName).then((result) => {
85-
console.log("The result is:");
86-
console.log(result);
87-
}).catch((err) => {
88-
console.log("An error occurred:");
89-
console.error(err);
90-
});
92+
const client = new Azure.ArmAnalysisservices.AnalysisServicesManagementClient(creds, subscriptionId);
93+
const resourceGroupName = "testresourceGroupName";
94+
const serverName = "testserverName";
95+
client.servers.getDetails(resourceGroupName, serverName).then((result) => {
96+
console.log("The result is:");
97+
console.log(result);
98+
}).catch((err) => {
99+
console.log("An error occurred:");
100+
console.error(err);
91101
});
92102
</script>
93103
</head>
@@ -99,5 +109,4 @@ See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to
99109

100110
- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)
101111

102-
103-
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fanalysisservices%2Farm-analysisservices%2FREADME.png)
112+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/analysisservices/arm-analysisservices/README.png)

0 commit comments

Comments
 (0)