@azure/identity-broker

中文文档
1.4.3发布于 2026/10/30MITTypeScriptESM + CJS近 30 天下载 7860

A native plugin for Azure Identity credentials to enable broker authentication such as WAM

原始使用文档
文档目录15 节
  1. Getting started
  2. Prerequisites
  3. Install the package
  4. Key concepts
  5. Parent window handles
  6. Microsoft account (MSA) passthrough
  7. Redirect URIs
  8. Azure Identity plugins
  9. Examples
  10. Use the default account for sign-in
  11. Troubleshooting
  12. Logging
  13. Next steps
  14. Provide feedback
  15. Contributing

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.

An authentication broker is an application that runs on a user’s machine that manages the authentication handshakes and token maintenance for connected accounts. Currently, only the Windows authentication broker, Web Account Manager (WAM), is supported.

Source code | Samples | API reference documentation | Microsoft Entra ID documentation

Getting started

import { useIdentityPlugin } from "@azure/identity";
import { nativeBrokerPlugin } from "@azure/identity-broker";

useIdentityPlugin(nativeBrokerPlugin);

Prerequisites

Note: For local development with @azure/identity-broker, you may need to install additional tools. node-gyp is used to compile addons for accessing system APIs. Installation requirements are listed in the node-gyp README.

On Linux, the library uses libsecret so you may need to install it. Depending on your distribution, you will need to run the following command:

  • Debian/Ubuntu: sudo apt-get install libsecret-1-dev
  • Red Hat-based: sudo yum install libsecret-devel
  • Arch Linux: sudo pacman -S libsecret

[!NOTE] Brokered authentication is currently only supported on Windows and Linux. macOS isn't yet supported.

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

Parent window handles

When authenticating with the broker via InteractiveBrowserCredential, a parent window handle is required to ensure that the authentication dialog is shown correctly over the requesting window. In the context of graphical user interfaces on devices, a window handle is a unique identifier that the operating system assigns to each window. For the Windows operating system, this handle is an integer value that serves as a reference to a specific window.

Microsoft account (MSA) passthrough

Microsoft accounts (MSA) are personal accounts created by users to access Microsoft services. MSA passthrough is a legacy configuration which enables users to get tokens to resources which normally don't accept MSA logins. This feature is only available to first-party applications. Users authenticating with an application that is configured to use MSA passthrough can set legacyEnableMsaPassthrough to true inside InteractiveBrowserCredentialNodeOptions.brokerOptions to allow these personal accounts to be listed by WAM.

Redirect URIs

Microsoft Entra applications rely on redirect URIs to determine where to send the authentication response after a user has logged in. To enable brokered authentication through WAM, a redirect URI matching the following pattern should be registered to the application:

ms-appx-web://Microsoft.AAD.BrokerPlugin/{client_id}

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 { useIdentityPlugin, InteractiveBrowserCredential } from "@azure/identity";
import { nativeBrokerPlugin } from "@azure/identity-broker";

useIdentityPlugin(nativeBrokerPlugin);

const credential = new InteractiveBrowserCredential({
  brokerOptions: {
    enabled: true,
    parentWindowHandle: new Uint8Array(0), // This should be a handle to the parent window
  },
});

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.

Notes: As of @azure/identity version 4.11.0-beta.1, DefaultAzureCredential provides support to sign-in via the Windows Web Account Manager. Enable native broker in your program as follows:

import { useIdentityPlugin, DefaultAzureCredential } from "@azure/identity";
import { nativeBrokerPlugin } from "@azure/identity-broker";

useIdentityPlugin(nativeBrokerPlugin);

const credential = new DefaultAzureCredential();

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 { useIdentityPlugin, InteractiveBrowserCredential } from "@azure/identity";
import { nativeBrokerPlugin } from "@azure/identity-broker";

useIdentityPlugin(nativeBrokerPlugin);

const credential = new InteractiveBrowserCredential({
  brokerOptions: {
    enabled: true,
    parentWindowHandle: new Uint8Array(0), // This should be a handle to the parent window
  },
});

// 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.substring(0, 10), "...");

For a complete example of using an Electron app for retrieving a window handle, see this sample.

Use the default account for sign-in

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.

import { useIdentityPlugin, InteractiveBrowserCredential } from "@azure/identity";
import { nativeBrokerPlugin } from "@azure/identity-broker";

useIdentityPlugin(nativeBrokerPlugin);

const credential = new InteractiveBrowserCredential({
  brokerOptions: {
    enabled: true,
    useDefaultBrokerAccount: true,
    parentWindowHandle: new Uint8Array(0), // This should be a handle to the parent window
  },
});

// 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), "...");

Troubleshooting

See the Azure Identity troubleshooting guide for details on how to diagnose various failure scenarios.

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.

版本与发布记录

@azure/identity-broker 共发布 349 个版本,首次发布于 2023/10/27;过去 12 个月发布了 83 个版本。

版本发布日期距今
1.4.3latest2026/10/308 天前
1.4.22026/09/161 个月前
1.4.12026/08/192 个月前
1.4.02026/04/106 个月前
1.3.1-alpha.20260310.1dev2026/03/117 个月前
1.3.1-alpha.20260309.22026/03/107 个月前

关于 @azure/identity-broker 的常见问题

@azure/identity-broker 是什么?

A native plugin for Azure Identity credentials to enable broker authentication such as WAM

如何安装 @azure/identity-broker?

在项目目录运行 npm install @azure/identity-broker,或使用 pnpm add / yarn add / bun add。

@azure/identity-broker 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@azure/identity-broker 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@azure/identity-broker 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@azure/identity-broker 可以商用吗?

@azure/identity-broker 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@azure/identity-broker 的下载量有多少?

根据 npm 官方下载统计,@azure/identity-broker 在 2026/10/08 – 2026/11/06 这 30 天内被下载 7,860 次,日均约 262 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@azure/identity-broker 还在维护吗?

最新版本 1.4.3 发布于 2026/10/30(8 天前);至今共发布 349 个版本,其中过去 12 个月发布了 83 个;首次发布于 2023/10/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。