@azure/identity-broker 1.0.2-alpha.20240917.2 → 1.0.2-alpha.20240926.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@ An authentication broker is an application that runs on a user’s machine that
|
|
|
8
8
|
|
|
9
9
|
## Getting started
|
|
10
10
|
|
|
11
|
-
```
|
|
12
|
-
import { nativeBrokerPlugin } from "@azure/identity-broker";
|
|
11
|
+
```ts snippet:getting_started
|
|
13
12
|
import { useIdentityPlugin } from "@azure/identity";
|
|
13
|
+
import { nativeBrokerPlugin } from "@azure/identity-broker";
|
|
14
14
|
|
|
15
15
|
useIdentityPlugin(nativeBrokerPlugin);
|
|
16
16
|
```
|
|
@@ -56,15 +56,15 @@ ms-appx-web://Microsoft.AAD.BrokerPlugin/{client_id}
|
|
|
56
56
|
|
|
57
57
|
As of `@azure/identity` version 2.0.0, the Identity client library for JavaScript includes a plugin API. This package (`@azure/identity-broker`) exports a plugin object that you must pass as an argument to the top-level `useIdentityPlugin` function from the `@azure/identity` package. Enable native broker in your program as follows:
|
|
58
58
|
|
|
59
|
-
```
|
|
60
|
-
import { nativeBrokerPlugin } from "@azure/identity-broker";
|
|
59
|
+
```ts snippet:using_plugins
|
|
61
60
|
import { useIdentityPlugin, InteractiveBrowserCredential } from "@azure/identity";
|
|
61
|
+
import { nativeBrokerPlugin } from "@azure/identity-broker";
|
|
62
62
|
|
|
63
63
|
useIdentityPlugin(nativeBrokerPlugin);
|
|
64
|
-
|
|
65
64
|
const credential = new InteractiveBrowserCredential({
|
|
66
65
|
brokerOptions: {
|
|
67
66
|
enabled: true,
|
|
67
|
+
parentWindowHandle: new Uint8Array(0), // This should be a handle to the parent window
|
|
68
68
|
},
|
|
69
69
|
});
|
|
70
70
|
```
|
|
@@ -75,32 +75,21 @@ After calling `useIdentityPlugin`, the native broker plugin is registered to the
|
|
|
75
75
|
|
|
76
76
|
Once the plugin is registered, you can enable WAM broker authentication by passing `brokerOptions` with an `enabled` property set to `true` to a credential constructor. In the following example, we use the `InteractiveBrowserCredential`.
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
import { nativeBrokerPlugin } from "@azure/identity-broker";
|
|
78
|
+
```ts snippet:usage_example
|
|
81
79
|
import { useIdentityPlugin, InteractiveBrowserCredential } from "@azure/identity";
|
|
80
|
+
import { nativeBrokerPlugin } from "@azure/identity-broker";
|
|
82
81
|
|
|
83
82
|
useIdentityPlugin(nativeBrokerPlugin);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
parentWindowHandle: <insert_current_window_handle>
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// We'll use the Microsoft Graph scope as an example
|
|
94
|
-
const scope = "https://graph.microsoft.com/.default";
|
|
95
|
-
|
|
96
|
-
// Print out part of the access token
|
|
97
|
-
console.log((await credential.getToken(scope)).token.substr(0, 10), "...");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
main().catch((error) => {
|
|
101
|
-
console.error("An error occurred:", error);
|
|
102
|
-
process.exit(1);
|
|
83
|
+
const credential = new InteractiveBrowserCredential({
|
|
84
|
+
brokerOptions: {
|
|
85
|
+
enabled: true,
|
|
86
|
+
parentWindowHandle: new Uint8Array(0), // This should be a handle to the parent window
|
|
87
|
+
},
|
|
103
88
|
});
|
|
89
|
+
// We'll use the Microsoft Graph scope as an example
|
|
90
|
+
const scope = "https://graph.microsoft.com/.default";
|
|
91
|
+
// Print out part of the access token
|
|
92
|
+
console.log((await credential.getToken(scope)).token.substring(0, 10), "...");
|
|
104
93
|
```
|
|
105
94
|
|
|
106
95
|
For a complete example of using an Electron app for retrieving a window handle, see [this sample](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity-broker/samples/v1/typescript/src/index.ts).
|
|
@@ -109,33 +98,22 @@ For a complete example of using an Electron app for retrieving a window handle,
|
|
|
109
98
|
|
|
110
99
|
When the `useDefaultBrokerAccount` option is set to `true`, the credential will attempt to silently use the default broker account. If using the default account fails, the credential will fall back to interactive authentication.
|
|
111
100
|
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
import { nativeBrokerPlugin } from "@azure/identity-broker";
|
|
101
|
+
```ts snippet:use_default_account
|
|
115
102
|
import { useIdentityPlugin, InteractiveBrowserCredential } from "@azure/identity";
|
|
103
|
+
import { nativeBrokerPlugin } from "@azure/identity-broker";
|
|
116
104
|
|
|
117
105
|
useIdentityPlugin(nativeBrokerPlugin);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
parentWindowHandle: <insert_current_window_handle>
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// We'll use the Microsoft Graph scope as an example
|
|
129
|
-
const scope = "https://graph.microsoft.com/.default";
|
|
130
|
-
|
|
131
|
-
// Print out part of the access token
|
|
132
|
-
console.log((await credential.getToken(scope)).token.substr(0, 10), "...");
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
main().catch((error) => {
|
|
136
|
-
console.error("An error occurred:", error);
|
|
137
|
-
process.exit(1);
|
|
106
|
+
const credential = new InteractiveBrowserCredential({
|
|
107
|
+
brokerOptions: {
|
|
108
|
+
enabled: true,
|
|
109
|
+
useDefaultBrokerAccount: true,
|
|
110
|
+
parentWindowHandle: new Uint8Array(0), // This should be a handle to the parent window
|
|
111
|
+
},
|
|
138
112
|
});
|
|
113
|
+
// We'll use the Microsoft Graph scope as an example
|
|
114
|
+
const scope = "https://graph.microsoft.com/.default";
|
|
115
|
+
// Print out part of the access token
|
|
116
|
+
console.log((await credential.getToken(scope)).token.substr(0, 10), "...");
|
|
139
117
|
```
|
|
140
118
|
|
|
141
119
|
## Troubleshooting
|
|
@@ -146,7 +124,7 @@ See the Azure Identity [troubleshooting guide][https://github.com/Azure/azure-sd
|
|
|
146
124
|
|
|
147
125
|
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
148
126
|
|
|
149
|
-
```
|
|
127
|
+
```ts snippet:logging
|
|
150
128
|
import { setLogLevel } from "@azure/logger";
|
|
151
129
|
|
|
152
130
|
setLogLevel("info");
|
package/dist/index.js
CHANGED
|
@@ -14,12 +14,17 @@ var msalNodeExtensions = require('@azure/msal-node-extensions');
|
|
|
14
14
|
*
|
|
15
15
|
* Example:
|
|
16
16
|
*
|
|
17
|
-
* ```
|
|
18
|
-
* import { useIdentityPlugin,
|
|
17
|
+
* ```ts snippet:using_plugins
|
|
18
|
+
* import { useIdentityPlugin, InteractiveBrowserCredential } from "@azure/identity";
|
|
19
19
|
* import { nativeBrokerPlugin } from "@azure/identity-broker";
|
|
20
20
|
*
|
|
21
|
-
* // Load the plugin
|
|
22
21
|
* useIdentityPlugin(nativeBrokerPlugin);
|
|
22
|
+
* const credential = new InteractiveBrowserCredential({
|
|
23
|
+
* brokerOptions: {
|
|
24
|
+
* enabled: true,
|
|
25
|
+
* parentWindowHandle: new Uint8Array(0), // This should be a handle to the parent window
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
23
28
|
* ```
|
|
24
29
|
*/
|
|
25
30
|
const nativeBrokerPlugin = (context) => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AzurePluginContext } from \"../../identity/src/plugins/provider\";\nimport { IdentityPlugin } from \"@azure/identity\";\nimport { NativeBrokerPlugin } from \"@azure/msal-node-extensions\";\n\n/**\n * A plugin that provides WAM Integration for `@azure/identity`\n * credentials. The plugin API is compatible with `@azure/identity` versions\n * 4.0.0 and later. Load this plugin using the `useIdentityPlugin`\n * function, imported from `@azure/identity`.\n *\n * Example:\n *\n * ```
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AzurePluginContext } from \"../../identity/src/plugins/provider\";\nimport { IdentityPlugin } from \"@azure/identity\";\nimport { NativeBrokerPlugin } from \"@azure/msal-node-extensions\";\n\n/**\n * A plugin that provides WAM Integration for `@azure/identity`\n * credentials. The plugin API is compatible with `@azure/identity` versions\n * 4.0.0 and later. Load this plugin using the `useIdentityPlugin`\n * function, imported from `@azure/identity`.\n *\n * Example:\n *\n * ```ts snippet:using_plugins\n * import { useIdentityPlugin, InteractiveBrowserCredential } from \"@azure/identity\";\n * import { nativeBrokerPlugin } from \"@azure/identity-broker\";\n *\n * useIdentityPlugin(nativeBrokerPlugin);\n * const credential = new InteractiveBrowserCredential({\n * brokerOptions: {\n * enabled: true,\n * parentWindowHandle: new Uint8Array(0), // This should be a handle to the parent window\n * },\n * });\n * ```\n */\n\nexport const nativeBrokerPlugin: IdentityPlugin = (context: unknown) => {\n const { nativeBrokerPluginControl } = context as AzurePluginContext;\n const brokerPlugin = new NativeBrokerPlugin();\n nativeBrokerPluginControl.setNativeBroker(brokerPlugin);\n};\n"],"names":["NativeBrokerPlugin"],"mappings":";;;;;;AAAA;AACA;AAMA;;;;;;;;;;;;;;;;;;;;AAoBG;AAEU,MAAA,kBAAkB,GAAmB,CAAC,OAAgB,KAAI;AACrE,IAAA,MAAM,EAAE,yBAAyB,EAAE,GAAG,OAA6B,CAAC;AACpE,IAAA,MAAM,YAAY,GAAG,IAAIA,qCAAkB,EAAE,CAAC;AAC9C,IAAA,yBAAyB,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;AAC1D;;;;"}
|
|
@@ -9,12 +9,17 @@ import { NativeBrokerPlugin } from "@azure/msal-node-extensions";
|
|
|
9
9
|
*
|
|
10
10
|
* Example:
|
|
11
11
|
*
|
|
12
|
-
* ```
|
|
13
|
-
* import { useIdentityPlugin,
|
|
12
|
+
* ```ts snippet:using_plugins
|
|
13
|
+
* import { useIdentityPlugin, InteractiveBrowserCredential } from "@azure/identity";
|
|
14
14
|
* import { nativeBrokerPlugin } from "@azure/identity-broker";
|
|
15
15
|
*
|
|
16
|
-
* // Load the plugin
|
|
17
16
|
* useIdentityPlugin(nativeBrokerPlugin);
|
|
17
|
+
* const credential = new InteractiveBrowserCredential({
|
|
18
|
+
* brokerOptions: {
|
|
19
|
+
* enabled: true,
|
|
20
|
+
* parentWindowHandle: new Uint8Array(0), // This should be a handle to the parent window
|
|
21
|
+
* },
|
|
22
|
+
* });
|
|
18
23
|
* ```
|
|
19
24
|
*/
|
|
20
25
|
export const nativeBrokerPlugin = (context) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEjE
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAmB,CAAC,OAAgB,EAAE,EAAE;IACrE,MAAM,EAAE,yBAAyB,EAAE,GAAG,OAA6B,CAAC;IACpE,MAAM,YAAY,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAC9C,yBAAyB,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;AAC1D,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AzurePluginContext } from \"../../identity/src/plugins/provider\";\nimport { IdentityPlugin } from \"@azure/identity\";\nimport { NativeBrokerPlugin } from \"@azure/msal-node-extensions\";\n\n/**\n * A plugin that provides WAM Integration for `@azure/identity`\n * credentials. The plugin API is compatible with `@azure/identity` versions\n * 4.0.0 and later. Load this plugin using the `useIdentityPlugin`\n * function, imported from `@azure/identity`.\n *\n * Example:\n *\n * ```ts snippet:using_plugins\n * import { useIdentityPlugin, InteractiveBrowserCredential } from \"@azure/identity\";\n * import { nativeBrokerPlugin } from \"@azure/identity-broker\";\n *\n * useIdentityPlugin(nativeBrokerPlugin);\n * const credential = new InteractiveBrowserCredential({\n * brokerOptions: {\n * enabled: true,\n * parentWindowHandle: new Uint8Array(0), // This should be a handle to the parent window\n * },\n * });\n * ```\n */\n\nexport const nativeBrokerPlugin: IdentityPlugin = (context: unknown) => {\n const { nativeBrokerPluginControl } = context as AzurePluginContext;\n const brokerPlugin = new NativeBrokerPlugin();\n nativeBrokerPluginControl.setNativeBroker(brokerPlugin);\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/identity-broker",
|
|
3
|
-
"version": "1.0.2-alpha.
|
|
3
|
+
"version": "1.0.2-alpha.20240926.2",
|
|
4
4
|
"sdk-type": "client",
|
|
5
5
|
"description": "A native plugin for Azure Identity credentials to enable broker authentication such as WAM",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,26 +8,27 @@
|
|
|
8
8
|
"types": "./types/identity-broker.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
|
|
11
|
+
"build": "npm run extract-api && tsc -p . && dev-tool run bundle",
|
|
11
12
|
"build:samples": "echo skipped",
|
|
12
13
|
"build:test": "tsc -p . && dev-tool run bundle",
|
|
13
|
-
"build": "npm run extract-api && tsc -p . && dev-tool run bundle",
|
|
14
14
|
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
15
15
|
"clean": "rimraf --glob dist dist-esm types \"*.tgz\" \"*.log\"",
|
|
16
16
|
"execute:samples": "echo skipped",
|
|
17
17
|
"extract-api": "tsc -p . && dev-tool run extract-api",
|
|
18
18
|
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
19
|
+
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
|
|
19
20
|
"integration-test:browser": "echo skipped",
|
|
20
21
|
"integration-test:node": "echo skipped",
|
|
21
|
-
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
|
|
22
|
-
"lint:fix": "eslint package.json api-extractor.json README.md src test --fix --fix-type [problem,suggestion]",
|
|
23
22
|
"lint": "eslint package.json api-extractor.json README.md src test",
|
|
23
|
+
"lint:fix": "eslint package.json api-extractor.json README.md src test --fix --fix-type [problem,suggestion]",
|
|
24
24
|
"pack": "npm pack 2>&1",
|
|
25
|
+
"test": "npm run clean && npm run build:test && npm run unit-test && npm run integration-test",
|
|
25
26
|
"test:browser": "npm run clean && npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
|
|
26
27
|
"test:node": "npm run clean && npm run build:test && npm run unit-test:node && npm run integration-test:node",
|
|
27
|
-
"test": "npm run
|
|
28
|
+
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
|
|
28
29
|
"unit-test:browser": "echo skipped",
|
|
29
|
-
"unit-test:node": "dev-tool run test:node-ts-input -- --timeout 300000 --exclude 'test/**/browser/**/*.spec.ts' 'test/**/**/*.spec.ts'",
|
|
30
|
-
"
|
|
30
|
+
"unit-test:node": "dev-tool run test:node-ts-input -- --timeout 300000 --exclude 'test/**/browser/**/*.spec.ts' --exclude 'test/snippets.spec.ts' 'test/**/**/*.spec.ts'",
|
|
31
|
+
"update-snippets": "dev-tool run update-snippets"
|
|
31
32
|
},
|
|
32
33
|
"files": [
|
|
33
34
|
"dist/",
|
|
@@ -64,14 +65,14 @@
|
|
|
64
65
|
"tslib": "^2.2.0"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
68
|
+
"@azure-tools/test-recorder": "^3.0.0",
|
|
69
|
+
"@azure-tools/test-utils": "^1.0.1",
|
|
67
70
|
"@azure/abort-controller": "^1.1.0",
|
|
68
71
|
"@azure/core-client": "^1.7.0",
|
|
69
72
|
"@azure/core-util": "^1.6.0",
|
|
70
73
|
"@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
|
|
71
74
|
"@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
|
|
72
75
|
"@azure/logger": "^1.0.4",
|
|
73
|
-
"@azure-tools/test-utils": "^1.0.1",
|
|
74
|
-
"@azure-tools/test-recorder": "^3.0.0",
|
|
75
76
|
"@microsoft/api-extractor": "^7.35.1",
|
|
76
77
|
"@types/mocha": "^10.0.0",
|
|
77
78
|
"@types/node": "^18.0.0",
|
|
@@ -81,8 +82,8 @@
|
|
|
81
82
|
"mocha": "^10.0.0",
|
|
82
83
|
"puppeteer": "^23.0.2",
|
|
83
84
|
"rimraf": "^5.0.1",
|
|
84
|
-
"
|
|
85
|
-
"
|
|
85
|
+
"sinon": "^17.0.0",
|
|
86
|
+
"typescript": "~5.6.2"
|
|
86
87
|
},
|
|
87
88
|
"//sampleConfiguration": {
|
|
88
89
|
"productName": "Azure Identity Brokered Auth Plugin",
|
|
@@ -8,12 +8,17 @@ import { IdentityPlugin } from '@azure/identity';
|
|
|
8
8
|
*
|
|
9
9
|
* Example:
|
|
10
10
|
*
|
|
11
|
-
* ```
|
|
12
|
-
* import { useIdentityPlugin,
|
|
11
|
+
* ```ts snippet:using_plugins
|
|
12
|
+
* import { useIdentityPlugin, InteractiveBrowserCredential } from "@azure/identity";
|
|
13
13
|
* import { nativeBrokerPlugin } from "@azure/identity-broker";
|
|
14
14
|
*
|
|
15
|
-
* // Load the plugin
|
|
16
15
|
* useIdentityPlugin(nativeBrokerPlugin);
|
|
16
|
+
* const credential = new InteractiveBrowserCredential({
|
|
17
|
+
* brokerOptions: {
|
|
18
|
+
* enabled: true,
|
|
19
|
+
* parentWindowHandle: new Uint8Array(0), // This should be a handle to the parent window
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
17
22
|
* ```
|
|
18
23
|
*/
|
|
19
24
|
export declare const nativeBrokerPlugin: IdentityPlugin;
|