@azure/identity-vscode

中文文档
2.2.3发布于 2026/10/30MITTypeScriptESM + CJS近 30 天下载 3.2万

Use the Azure Account extension for Visual Studio Code to authenticate with Azure Identity

原始使用文档
文档目录11 节
  1. Prerequisites
  2. Install the package
  3. Key concepts
  4. Azure Identity Plugins
  5. Visual Studio Code Authentication
  6. Examples
  7. Troubleshooting
  8. Logging
  9. Next steps
  10. Provide Feedback
  11. Contributing

Azure Identity Plugin for Visual Studio Code Authentication

This package provides a plugin to the Azure Identity library for JavaScript (@azure/identity) that enables authentication through the "Azure Resources" extension for Visual Studio Code. This plugin provides the dependencies of the VisualStudioCodeCredential in @azure/identity and enables it for use on its own or as part of DefaultAzureCredential.

Source code | Samples

Prerequisites

Note: For local development with @azure/identity-vscode, 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] Visual Studio Code 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-dev @azure/identity-vscode

Supported Environments

Azure Identity plugins for JavaScript support stable (even numbered) versions of Node.js starting from v12. While the plugins may run in other Node versions, no support is guaranteed. @azure/identity-vscode 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 4.11.0, the Identity client library for JavaScript includes a plugin API. This package (@azure/identity-vscode) exports a plugin object that you must pass as an argument to the top-level useIdentityPlugin function from the @azure/identity package. Enable authentication through the "Azure Resource" extension for Visual Studio Code as follows:

import { useIdentityPlugin } from "@azure/identity";
import { vsCodePlugin } from "@azure/identity-vscode";

useIdentityPlugin(vsCodePlugin);

After calling useIdentityPlugin, the VisualStudioCodeCredential from the @azure/identity package will be enabled. If this plugin is not used, then VisualStudioCodeCredential will throw a CredentialUnavailableError, and it will not be available as part of DefaultAzureCredential.

Visual Studio Code Authentication

VisualStudioCodeCredential uses the authentication record from the "Azure Resources" extension. To use this credential, you must sign in to your Azure account using the extension. To do so, open Visual Studio Code, ensure that the extension is installed, and sign in from Command Palette using the "Azure: Sign In" option to open a browser window and sign in to Azure. Alternatively, you can select "Azure: Sign In with Device Code" to use the device code flow.

After signing in, you may need to select a subscription (for example, if you have multiple Azure subscriptions), and you can change the active subscription by using the menu to select the "Azure: Select Subscriptions" entry.

The plugin automatically detects the authentication record stored by the Azure Resources extension and uses it for authentication.

Examples

Once the plugin is registered, you can use VisualStudioCodeCredential in a similar fashion to the other credential classes in @azure/identity:

import { useIdentityPlugin, VisualStudioCodeCredential } from "@azure/identity";
import { vsCodePlugin } from "@azure/identity-vscode";

useIdentityPlugin(vsCodePlugin);

const credential = new VisualStudioCodeCredential();

// The graph.microsoft.com scope is used 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), "...");

You can also use DefaultAzureCredential, which will attempt to authenticate using the "Azure Resources" extension for Visual Studio Code if it's available:

import { useIdentityPlugin, DefaultAzureCredential } from "@azure/identity";
import { vsCodePlugin } from "@azure/identity-vscode";

useIdentityPlugin(vsCodePlugin);

// With the plugin enabled above, `DefaultAzureCredential` will use
// Visual Studio Code's "Azure Resources" extension to authenticate if
// it is available.
const credential = new DefaultAzureCredential();

// This will print a JWT access_token and its expiration timestamp
// The graph.microsoft.com scope is used as an example
console.log("Token:", await credential.getToken("https://graph.microsoft.com/.default"));

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, please read the contributing guide to learn more about how to build and test the code.

版本与发布记录

@azure/identity-vscode 共发布 417 个版本,首次发布于 2021/06/23;过去 12 个月发布了 72 个版本。

版本发布日期距今
2.2.3latest2026/10/308 天前
2.2.22026/09/161 个月前
2.2.12026/08/192 个月前
2.2.02026/04/106 个月前
2.1.0-alpha.20260310.1dev2026/03/117 个月前
2.1.0-alpha.20260309.22026/03/107 个月前

其他发布通道:beta → 2.0.0-beta.1,dev → 2.1.0-alpha.20260310.1。

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

@azure/identity-vscode 是什么?

Use the Azure Account extension for Visual Studio Code to authenticate with Azure Identity

如何安装 @azure/identity-vscode?

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

@azure/identity-vscode 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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

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

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