Skip to content

Commit c6fb107

Browse files
authored
identity support 30 (Azure#16254)
1 parent b7ed37e commit c6fb107

40 files changed

+825
-605
lines changed

sdk/machinelearningservices/arm-machinelearningservices/README.md

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,100 @@
11
## Azure AzureMachineLearningWorkspaces SDK for JavaScript
22

3-
This package contains an isomorphic SDK for AzureMachineLearningWorkspaces.
3+
This package contains an isomorphic SDK (runs both in Node.js and in browsers) for AzureMachineLearningWorkspaces.
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-machinelearningservices` 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-machinelearningservices
22+
npm install --save @azure/arm-machinelearningservices @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 - client creation and list operations 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 list operations as an example written in JavaScript.
2642

2743
##### Sample code
2844

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");
45+
```javascript
46+
const { DefaultAzureCredential } = require("@azure/identity");
3247
const { AzureMachineLearningWorkspaces } = require("@azure/arm-machinelearningservices");
3348
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
3449

35-
msRestNodeAuth.interactiveLogin().then((creds) => {
36-
const client = new AzureMachineLearningWorkspaces(creds, subscriptionId);
37-
client.operations.list().then((result) => {
38-
console.log("The result is:");
39-
console.log(result);
40-
});
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 AzureMachineLearningWorkspaces(creds, subscriptionId);
54+
55+
client.operations.list().then((result) => {
56+
console.log("The result is:");
57+
console.log(result);
4158
}).catch((err) => {
59+
console.log("An error occurred:");
4260
console.error(err);
4361
});
4462
```
4563

46-
#### browser - Authentication, client creation and list operations as an example written in JavaScript.
47-
48-
##### Install @azure/ms-rest-browserauth
64+
#### browser - Authentication, client creation, and list operations as an example written in JavaScript.
4965

50-
```bash
51-
npm install @azure/ms-rest-browserauth
52-
```
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.
5369

5470
##### Sample code
5571

56-
See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.
57-
5872
- index.html
73+
5974
```html
6075
<!DOCTYPE html>
6176
<html lang="en">
6277
<head>
6378
<title>@azure/arm-machinelearningservices sample</title>
64-
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
6579
<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>
80+
<script src="node_modules/@azure/identity/dist/index.js"></script>
6781
<script src="node_modules/@azure/arm-machinelearningservices/dist/arm-machinelearningservices.js"></script>
6882
<script type="text/javascript">
6983
const subscriptionId = "<Subscription_Id>";
70-
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+
{
7188
clientId: "<client id for your Azure AD app>",
72-
tenant: "<optional tenant for your organization>"
89+
tenantId: "<optional tenant for your organization>"
7390
});
74-
authManager.finalizeLogin().then((res) => {
75-
if (!res.isLoggedIn) {
76-
// may cause redirects
77-
authManager.login();
78-
}
79-
const client = new Azure.ArmMachinelearningservices.AzureMachineLearningWorkspaces(res.creds, subscriptionId);
80-
client.operations.list().then((result) => {
81-
console.log("The result is:");
82-
console.log(result);
83-
}).catch((err) => {
84-
console.log("An error occurred:");
85-
console.error(err);
86-
});
91+
const client = new Azure.ArmMachinelearningservices.AzureMachineLearningWorkspaces(creds, subscriptionId);
92+
client.operations.list().then((result) => {
93+
console.log("The result is:");
94+
console.log(result);
95+
}).catch((err) => {
96+
console.log("An error occurred:");
97+
console.error(err);
8798
});
8899
</script>
89100
</head>

sdk/machinelearningservices/arm-machinelearningservices/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"name": "@azure/arm-machinelearningservices",
33
"author": "Microsoft Corporation",
44
"description": "AzureMachineLearningWorkspaces Library with typescript type definitions for node.js and browser.",
5-
"version": "4.0.0",
5+
"version": "4.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/azureMachineLearningWorkspaces.js",
2122
"types": "./esm/azureMachineLearningWorkspaces.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/machinelearningservices/arm-machinelearningservices/src/azureMachineLearningWorkspaces.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";
@@ -31,11 +32,16 @@ class AzureMachineLearningWorkspaces extends AzureMachineLearningWorkspacesConte
3132

3233
/**
3334
* Initializes a new instance of the AzureMachineLearningWorkspaces class.
34-
* @param credentials Credentials needed for the client to connect to Azure.
35+
* @param credentials Credentials needed for the client to connect to Azure. Credentials
36+
* implementing the TokenCredential interface from the @azure/identity package are recommended. For
37+
* more information about these credentials, see
38+
* {@link https://www.npmjs.com/package/@azure/identity}. Credentials implementing the
39+
* ServiceClientCredentials interface from the older packages @azure/ms-rest-nodeauth and
40+
* @azure/ms-rest-browserauth are also supported.
3541
* @param subscriptionId Azure subscription identifier.
3642
* @param [options] The parameter options
3743
*/
38-
constructor(credentials: msRest.ServiceClientCredentials, subscriptionId: string, options?: Models.AzureMachineLearningWorkspacesOptions) {
44+
constructor(credentials: msRest.ServiceClientCredentials | TokenCredential, subscriptionId: string, options?: Models.AzureMachineLearningWorkspacesOptions) {
3945
super(credentials, subscriptionId, options);
4046
this.operations = new operations.Operations(this);
4147
this.workspaces = new operations.Workspaces(this);

sdk/machinelearningservices/arm-machinelearningservices/src/azureMachineLearningWorkspacesContext.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,29 @@
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-machinelearningservices";
15-
const packageVersion = "4.0.0";
16+
const packageVersion = "4.1.0";
1617

1718
export class AzureMachineLearningWorkspacesContext extends msRestAzure.AzureServiceClient {
18-
credentials: msRest.ServiceClientCredentials;
19+
credentials: msRest.ServiceClientCredentials | TokenCredential;
1920
subscriptionId: string;
2021
apiVersion?: string;
2122

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

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

2643
##### Sample code
2744

28-
```typescript
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 { ManagedApplicationClient, ManagedApplicationModels, ManagedApplicationMappers } from "@azure/arm-managedapplications";
45+
```javascript
46+
const { DefaultAzureCredential } = require("@azure/identity");
47+
const { ManagedApplicationClient } = require("@azure/arm-managedapplications");
3348
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
3449

35-
msRestNodeAuth.interactiveLogin().then((creds) => {
36-
const client = new ManagedApplicationClient(creds, subscriptionId);
37-
client.listOperations().then((result) => {
38-
console.log("The result is:");
39-
console.log(result);
40-
});
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 ManagedApplicationClient(creds, subscriptionId);
54+
55+
client.listOperations().then((result) => {
56+
console.log("The result is:");
57+
console.log(result);
4158
}).catch((err) => {
59+
console.log("An error occurred:");
4260
console.error(err);
4361
});
4462
```
4563

46-
#### browser - Authentication, client creation and listOperations as an example written in JavaScript.
47-
48-
##### Install @azure/ms-rest-browserauth
64+
#### browser - Authentication, client creation, and listOperations as an example written in JavaScript.
4965

50-
```bash
51-
npm install @azure/ms-rest-browserauth
52-
```
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.
5369

5470
##### Sample code
5571

56-
See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.
57-
5872
- index.html
73+
5974
```html
6075
<!DOCTYPE html>
6176
<html lang="en">
6277
<head>
6378
<title>@azure/arm-managedapplications sample</title>
64-
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
6579
<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>
80+
<script src="node_modules/@azure/identity/dist/index.js"></script>
6781
<script src="node_modules/@azure/arm-managedapplications/dist/arm-managedapplications.js"></script>
6882
<script type="text/javascript">
6983
const subscriptionId = "<Subscription_Id>";
70-
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+
{
7188
clientId: "<client id for your Azure AD app>",
72-
tenant: "<optional tenant for your organization>"
89+
tenantId: "<optional tenant for your organization>"
7390
});
74-
authManager.finalizeLogin().then((res) => {
75-
if (!res.isLoggedIn) {
76-
// may cause redirects
77-
authManager.login();
78-
}
79-
const client = new Azure.ArmManagedapplications.ManagedApplicationClient(res.creds, subscriptionId);
80-
client.listOperations().then((result) => {
81-
console.log("The result is:");
82-
console.log(result);
83-
}).catch((err) => {
84-
console.log("An error occurred:");
85-
console.error(err);
86-
});
91+
const client = new Azure.ArmManagedapplications.ManagedApplicationClient(creds, subscriptionId);
92+
client.listOperations().then((result) => {
93+
console.log("The result is:");
94+
console.log(result);
95+
}).catch((err) => {
96+
console.log("An error occurred:");
97+
console.error(err);
8798
});
8899
</script>
89100
</head>
@@ -95,4 +106,4 @@ See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to
95106

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

98-
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmanagedapplications%2Farm-managedapplications%2FREADME.png)
109+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/managedapplications/arm-managedapplications/README.png)

0 commit comments

Comments
 (0)