@azure/identity-broker v1.0.0
Azure Identity plugin for brokered authentication
This package provides a plugin to the Azure Identity library for JavaScript (@azure/identity
) that enables using an authentication broker such as WAM.
Getting started
import { nativeBrokerPlugin } from "@azure/identity-broker";
import { useIdentityPlugin } from "@azure/identity";
useIdentityPlugin(nativeBrokerPlugin);
Prerequisites
Install the package
This package is designed to be used with Azure Identity for JavaScript. Install both @azure/identity
and this package using npm
:
npm install --save @azure/identity
npm install --save @azure/identity-broker
Supported environments
Azure Identity plugins for JavaScript support stable (even numbered) versions of Node.js starting from v18. While the plugins may run in other Node.js versions, no support is guaranteed. @azure/identity-broker
does not support browser environments.
Key concepts
If this is your first time using @azure/identity
or Microsoft Entra ID, we recommend that you read Using @azure/identity
with Microsoft Entra ID first. This document will give you a deeper understanding of the platform and how to configure your Azure account correctly.
Azure Identity plugins
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:
import { nativeBrokerPlugin } from "@azure/identity-broker";
import { useIdentityPlugin, InteractiveBrowserCredential } from "@azure/identity";
useIdentityPlugin(nativeBrokerPlugin);
const credential = new InteractiveBrowserCredential({
brokerOptions: {
enabled: true,
},
});
After calling useIdentityPlugin
, the native broker plugin is registered to the @azure/identity
package and will be available on the InteractiveBrowserCredential
that supports WAM broker authentication. This credential has brokerOptions
in the constructor options.
Examples
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
.
import { nativeBrokerPlugin } from "@azure/identity-broker";
import { useIdentityPlugin, InteractiveBrowserCredential } from "@azure/identity";
useIdentityPlugin(nativeBrokerPlugin);
async function main() {
const credential = new InteractiveBrowserCredential({
brokerOptions: {
enabled: true,
},
});
// We'll use the Microsoft Graph scope as an example
const scope = "https://graph.microsoft.com/.default";
// Print out part of the access token
console.log((await credential.getToken(scope)).token.substr(0, 10), "...");
}
main().catch((error) => {
console.error("An error occurred:", error);
process.exit(1);
});
Troubleshooting
Logging
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
:
import { setLogLevel } from ("@azure/logger");
setLogLevel("info");
Next steps
Provide feedback
If you encounter bugs or have suggestions, please open an issue.
Contributing
If you'd like to contribute to this library, see the contributing guide to learn more about how to build and test the code.
2 days ago
3 days ago
4 days ago
5 days ago
6 days ago
10 days ago
13 days ago
16 days ago
17 days ago
19 days ago
20 days ago
23 days ago
24 days ago
26 days ago
27 days ago
30 days ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
6 months ago
6 months ago
6 months ago
6 months ago
7 months ago
7 months ago