@equinor/fusion-framework-module-azure-identity

中文文档
0.4.0发布于 2026/11/12ISCTypeScriptES Module近 30 天下载 8253

Fusion Framework authentication module using Azure Identity. Supports ambient credentials (DefaultAzureCredential), interactive browser login, and static token modes.

原始使用文档
文档目录17 节
  1. When to use
  2. Install
  3. Quick start
  4. Default credential (CI/CD, managed identity)
  5. Interactive browser login
  6. Static token
  7. Acquiring tokens
  8. Authentication modes
  9. default_credential — ambient environment
  10. interactive — browser-based login
  11. token_only — static access token
  12. Operational telemetry
  13. Testing
  14. Token cache persistence
  15. Configurator API
  16. Exports
  17. /mock subpath

@equinor/fusion-framework-module-azure-identity

Azure Identity authentication module for the Fusion Framework. Provides three authentication modes — ambient credentials, interactive browser login, and static token — all registering under the 'auth' module slot as a drop-in replacement for @equinor/fusion-framework-module-msal-node.

When to use

ScenarioMode
CI/CD with OIDC (GitHub Actions azure/login, Azure Pipelines)default_credential
Managed identity (Azure VMs, App Service, Container Apps)default_credential
Azure CLI login (az login) flowing through automaticallydefault_credential
CLI tools requiring user sign-in via browserinteractive
Scripts with a pre-obtained FUSION_TOKENtoken_only

Both this module and @equinor/fusion-framework-module-msal-node register under the 'auth' slot, so only one can be active at a time.

Install

pnpm add @equinor/fusion-framework-module-azure-identity

Quick start

Default credential (CI/CD, managed identity)

No configuration needed — credentials are resolved from the environment automatically.

import { enableAzureIdentityAuth } from '@equinor/fusion-framework-module-azure-identity';

enableAzureIdentityAuth(configurator);

Interactive browser login

Opens the user's default browser for Azure AD login. Tokens and the AuthenticationRecord are cached to the OS keychain so subsequent invocations resolve silently.

import { enableAzureIdentityInteractive } from '@equinor/fusion-framework-module-azure-identity';

enableAzureIdentityInteractive(configurator, {
  tenantId: '3aa4a235-...',
  clientId: 'a318b8e1-...',
  redirectPort: 49741,
  onOpen: (url) => console.log(`Open: ${url}`),
});

Static token

Use a pre-obtained access token. Login and logout are not supported.

import { enableAzureIdentityTokenOnly } from '@equinor/fusion-framework-module-azure-identity';

enableAzureIdentityTokenOnly(configurator, process.env.FUSION_TOKEN!);

Acquiring tokens

After initialisation, acquire tokens the same way as with the MSAL module:

const token = await framework.auth.acquireAccessToken({
  request: { scopes: ['api://my-api/.default'] },
});

Authentication modes

default_credential — ambient environment

Uses DefaultAzureCredential which tries these sources in order:

  1. Environment variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_FEDERATED_TOKEN_FILE, etc.)
  2. Workload identity (Kubernetes pods with Azure Workload Identity)
  3. Managed identity (Azure VMs, App Service, Container Apps)
  4. Azure CLI (az login session)
  5. Azure PowerShell (Connect-AzAccount session)
  6. Azure Developer CLI (azd auth login session)

In GitHub Actions after azure/login@v3 with OIDC, option 1 is used automatically.

login() and logout() throw — there is no interactive session to manage.

interactive — browser-based login

Uses InteractiveBrowserCredential with an authorization code flow through a localhost redirect. Designed for CLI tools (ffc auth login, ffc auth token).

  • On first run, opens the browser for Azure AD login
  • Saves the AuthenticationRecord to OS-level secure storage via @azure/msal-node-extensions (Keychain on macOS, DPAPI on Windows, libsecret on Linux)
  • On subsequent runs, loads the record and acquires tokens silently from the cached credential
// Explicit login (opens browser)
const record = await framework.auth.login({
  request: { scopes: ['api://my-api/.default'] },
});
console.log('Logged in as', record.username);

// Silent token acquisition (no browser)
const token = await framework.auth.acquireAccessToken({
  request: { scopes: ['api://my-api/.default'] },
});

// Clear cached credentials
await framework.auth.logout();

token_only — static access token

Returns a pre-obtained token string. login() and logout() throw.

Operational telemetry

When a telemetry module is registered alongside this module, the provider records acquireToken (which acquireAccessToken uses), login and logout as fusion.azure-identity.acquire-token.duration, fusion.azure-identity.login.duration and fusion.azure-identity.logout.duration, with one sanitized .failure exception per failure. Tokens, scopes, accounts, device codes and original errors are never recorded, and results and errors are unchanged. Static token_only providers are never instrumented, and calls for a telemetry export request, marked with markTelemetryExportRequest, are not recorded. Without telemetry the provider is left untouched; the package remains Node-compatible either way.

Testing

token_only mode already avoids real Azure AD traffic, but it is rigid: a single fixed token, no expiry simulation, and login/logout always throw. For tests that need to exercise sign-in, sign-out, or token-refresh/expiry logic, use MockAuthProvider from the /mock subpath instead:

import { enableAuthMock } from '@equinor/fusion-framework-module-azure-identity/mock';

// seed the identity/state up front; omit the callback for a default, already-signed-in identity
const auth = enableAuthMock(configurator, (auth) => {
  auth.setAccount({ username: '[email protected]', signedOut: true });
});

// drive login/logout and inspect the resulting tokens directly
await auth.login({ request: { scopes: ['User.Read'] } });
const token = await auth.acquireAccessToken({ request: { scopes: ['User.Read'] } });

// simulate an expired token, to exercise a consuming application's refresh path
auth.setExpiresOn(new Date(Date.now() - 1000));

MockAuthProvider registers exactly like any other IAuthProvider implementation — no special-cased wiring — and makes no real @azure/identity network calls.

Token cache persistence

The module registers cachePersistencePlugin from @azure/identity-cache-persistence at load time, enabling encrypted OS-level token caching:

PlatformBackend
macOSKeychain
WindowsDPAPI
Linuxlibsecret

In interactive mode, the AuthenticationRecord (account metadata that tells the credential which cached tokens to look up) is additionally stored via @azure/msal-node-extensions secure persistence.

Configurator API

The generic enableAzureIdentityAuth accepts a callback for full control:

enableAzureIdentityAuth(configurator, (builder) => {
  // Option A — mode-specific setter
  builder.setInteractive({ tenantId, clientId, redirectPort: 49741 });

  // Option B — full config object (discriminated union)
  builder.setConfig({
    mode: 'interactive',
    tenantId,
    clientId,
    redirectPort: 49741,
  });

  // Option C — default credential (no args)
  builder.setDefaultCredential();

  // Option D — static token
  builder.setTokenOnly(token);
});

Exports

ExportDescription
enableAzureIdentityAuthGeneric enabler with configurator callback
enableAzureIdentityDefaultCredentialOne-liner enabler for default_credential mode
enableAzureIdentityInteractiveOne-liner enabler for interactive mode
enableAzureIdentityTokenOnlyOne-liner enabler for token_only mode
AzureIdentityAuthConfiguratorConfigurator class with type-safe setters
AzureIdentityAuthConfigDiscriminated union config type
InteractiveAuthOptionsOptions for interactive mode
AuthProviderDefaultCredentialProvider class for ambient credentials
AuthProviderInteractiveBrowserProvider class for browser login
AuthProviderTokenOnlyProvider class for static tokens
IAuthProviderAuth provider interface
AzureIdentityModuleModule type for generic parameters
azureIdentityModuleRaw module definition

/mock subpath

ExportDescription
MockAuthProviderConfigurable IAuthProvider test double — login/logout work, token and expiry are settable
MockAuthProviderOptionsConstructor options for MockAuthProvider
enableAuthMockRegisters a MockAuthProvider as the 'auth' module and returns it
createAuthMockModuleBuilds the mock module descriptor for a given MockAuthProvider

版本与发布记录

@equinor/fusion-framework-module-azure-identity 共发布 14 个版本,首次发布于 2026/04/29;过去 12 个月发布了 14 个版本。

版本发布日期距今
0.4.0latest2026/11/121 天前
0.4.0-next.1next2026/11/112 天前
0.4.0-next.02026/10/2816 天前
0.3.42026/10/1727 天前
0.3.4-trusted-publishing-20261015-9dfe7602cd2a49a8a9df00d62c26e7304a82a85atrusted-publishing-202610152026/10/1629 天前
0.3.32026/10/121 个月前

关于 @equinor/fusion-framework-module-azure-identity 的常见问题

@equinor/fusion-framework-module-azure-identity 是什么?

Fusion Framework authentication module using Azure Identity. Supports ambient credentials (DefaultAzureCredential), interactive browser login, and static token modes.

如何安装 @equinor/fusion-framework-module-azure-identity?

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

@equinor/fusion-framework-module-azure-identity 支持 TypeScript 吗?

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

@equinor/fusion-framework-module-azure-identity 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@equinor/fusion-framework-module-azure-identity 可以商用吗?

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

@equinor/fusion-framework-module-azure-identity 的下载量有多少?

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

@equinor/fusion-framework-module-azure-identity 还在维护吗?

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