你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

@azure/identity package

AggregateAuthenticationError

提供一个 errors 数组,其中包含 AuthenticationError 实例,用于通过 ChainedTokenCredential 中的凭据进行身份验证失败。

AuthenticationError

提供有关使用 Azure Active Directory 进行身份验证失败的详细信息。 字段 errorResponse 包含有关特定故障的更多详细信息。

AuthenticationRequiredError

尝试以无提示方式检索令牌后用于强制进行身份验证的错误。

AuthorizationCodeCredential

使用通过授权代码流获取的授权代码启用身份验证以Microsoft Entra ID,如Microsoft Entra ID文档中更详细地介绍:

https://learn.microsoft.com/entra/identity-platform/v2-oauth2-auth-code-flow

AzureCliCredential

此凭据将通过 Azure CLI ('az') 命令行工具使用当前登录的用户登录信息。 为此,它将使用 Azure CLI 命令“az account get-access-token”读取用户访问令牌和过期时间。

AzureDeveloperCliCredential

Azure Developer CLI是一种命令行界面工具,允许开发人员在 Azure 中创建、管理和部署资源。 它基于 Azure CLI 构建,提供特定于 Azure 开发人员的其他功能。 它允许用户以用户和/或服务主体的身份针对Microsoft Entra ID进行身份验证。 AzureDeveloperCliCredential 在开发环境中进行身份验证,并代表Azure Developer CLI中登录的用户或服务主体获取令牌。 它充当登录用户或服务主体的Azure Developer CLI,并在下方执行 Azure CLI 命令,针对Microsoft Entra ID对应用程序进行身份验证。

配置 AzureDeveloperCliCredential

若要使用此凭据,开发人员需要使用以下命令之一在本地Azure Developer CLI进行身份验证:

  1. 在 Azure Developer CLI 中运行“azd auth login”,以用户身份以交互方式进行身份验证。
  2. 运行“azd auth login --client-id clientID --client-secret clientSecret --tenant-id tenantID”以服务主体身份进行身份验证。

根据组织中的刷新令牌有效性,可能需要在特定时间段后重复此过程。 通常,刷新令牌的有效期为几周到几个月。 AzureDeveloperCliCredential 将提示你再次登录。

AzurePowerShellCredential

此凭据将使用Azure PowerShell模块中当前登录的用户信息。 为此,它将使用 Azure PowerShell 命令读取用户访问令牌并过期时间Get-AzAccessToken -ResourceUrl {ResourceScope}

ChainedTokenCredential

允许按顺序尝试多个 TokenCredential 实现,直到其中一个 getToken 方法返回访问令牌为止。

ClientAssertionCredential

使用 JWT 断言对服务主体进行身份验证。

ClientCertificateCredential

使用分配给应用注册的 PEM 编码证书启用身份验证以Microsoft Entra ID。 有关如何配置证书身份验证的详细信息,可在此处找到:

https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-certificate-credentials#register-your-certificate-with-azure-ad

ClientSecretCredential

允许使用为应用注册生成的客户端密码Microsoft Entra ID身份验证。 有关如何配置客户端密码的详细信息,可在此处找到:

https://learn.microsoft.com/entra/identity-platform/quickstart-configure-app-access-web-apis#add-credentials-to-your-web-application

CredentialUnavailableError

这表示在链接凭据中尝试的凭据不能用作凭据。 与其将其视为应停止链的错误,不如将其捕获,链继续

DefaultAzureCredential

提供适用于大多数使用 Azure SDK 的应用程序的默认 ChainedTokenCredential 配置。

DeviceCodeCredential

使用用户可以输入https://microsoft.com/devicelogin的设备代码启用身份验证以Microsoft Entra ID。

EnvironmentCredential

允许使用客户端密码或证书Microsoft Entra ID身份验证,或者作为具有用户名和密码的用户进行身份验证。

InteractiveBrowserCredential

允许使用交互式登录流在 Web 浏览器中Microsoft Entra ID身份验证。

ManagedIdentityCredential

尝试使用部署环境中可用的托管标识进行身份验证。 此身份验证类型适用于 Azure VM、App 服务 实例、Azure Functions应用程序、Azure Kubernetes 服务、Azure Service Fabric 实例以及 Azure Cloud Shell内部。

有关配置托管标识的详细信息,可在此处找到: https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview

OnBehalfOfCredential

启用身份验证以使用“代表”流Microsoft Entra ID。

UsernamePasswordCredential

启用身份验证以使用用户的用户名和密码Microsoft Entra ID。 此凭据需要高度信任,因此仅当无法使用其他更安全的凭据类型时,才应使用它。

VisualStudioCodeCredential

使用 VSCode 扩展“Azure 帐户”提供的凭据连接到 Azure。 用户通过扩展登录后,此凭据可以共享扩展缓存的同一刷新令牌。

这是一个已知问题,即此凭据不适用于 0.9.11 以上的 Azure 帐户扩展版本。 正在对此问题进行长期修复。 同时,请考虑使用 AzureCliCredential 进行身份验证。

WorkloadIdentityCredential

工作负载标识身份验证是 Azure 中的一项功能,它允许在虚拟机 (VM) 上运行的应用程序访问其他 Azure 资源,而无需服务主体或托管标识。 使用工作负载标识身份验证,应用程序使用自己的标识(而不是共享服务主体或托管标识)进行身份验证。 工作负载标识身份验证使用服务帐户凭据的概念 (SAC) ,这些凭据由 Azure 自动创建并安全地存储在 VM 中。 通过使用工作负载标识身份验证,可以避免需要为每个 VM 上的每个应用程序管理和轮换服务主体或托管标识。 此外,由于 SAC 由 Azure 自动创建和管理,因此无需担心存储和保护敏感凭据本身。 WorkloadIdentityCredential 支持在 Azure Kubernetes 上Microsoft Entra Workload ID身份验证,并使用 Azure Kubernetes 环境中提供的 SAC 获取令牌。 有关详细信息,请参阅Microsoft Entra Workload ID

接口

AccessToken

表示具有过期时间的访问令牌。

AuthenticationRecord

用于在缓存中查找缓存令牌的记录。

AuthenticationRequiredErrorOptions

AuthenticationRequiredError 的可选参数

AuthorityValidationOptions

提供用于配置标识库在Microsoft Entra ID身份验证请求期间如何执行授权验证的选项。

AuthorizationCodeCredentialOptions

AuthorizationCodeCredential 的选项

AzureCliCredentialOptions

AzureCliCredential 的选项

AzureDeveloperCliCredentialOptions

AzureDeveloperCliCredential 的选项

AzurePowerShellCredentialOptions

AzurePowerShellCredential 的选项

BrokerAuthOptions

InteractiveBrowserCredential 支持 WAM Broker 身份验证的配置选项。

BrokerDisabledOptions

禁用 WAM 代理身份验证时的参数。

BrokerEnabledOptions

启用 WAM 代理身份验证时的参数。

BrowserCustomizationOptions

浏览器自定义的共享配置选项

ClientAssertionCredentialOptions

ClientAssertionCredential 的选项

ClientCertificateCredentialOptions

ClientCertificateCredential 类的可选参数。

ClientCertificatePEMCertificate

ClientCertificateCredential 的必需配置选项,包含 PEM 证书的字符串内容

ClientCertificatePEMCertificatePath

ClientCertificateCredential 的必需配置选项,以及 PEM 证书的路径。

ClientSecretCredentialOptions

ClientSecretCredential 类的可选参数。

CredentialPersistenceOptions

支持持久令牌缓存的凭据的共享配置选项。

DefaultAzureCredentialClientIdOptions

提供用于配置 DefaultAzureCredential 类的选项。 此变体支持 managedIdentityClientId 而不是 managedIdentityResourceId,因为两者只支持其中一个。

DefaultAzureCredentialOptions

提供用于配置 DefaultAzureCredential 类的选项。

DefaultAzureCredentialResourceIdOptions

提供用于配置 DefaultAzureCredential 类的选项。 此变体支持 managedIdentityResourceId 而不是 managedIdentityClientId,因为两者只支持其中一个。

DeviceCodeCredentialOptions

为 Node.js 定义 InteractiveBrowserCredential 类的选项。

DeviceCodeInfo

提供必须输入代码的用户代码和验证 URI。 此外,还会向用户显示一条消息,其中包含包含这些详细信息的说明。

EnvironmentCredentialOptions

允许身份验证Microsoft Entra ID,具体取决于可用的环境变量。 定义 EnvironmentCredential 类的选项。

ErrorResponse

有关详细信息,请参阅官方文档:

https://learn.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-oauth-code#error-response-1

注意:本文档适用于 v1 OAuth 支持,但相同的错误响应详细信息仍适用于 v2。

GetTokenOptions

定义 TokenCredential.getToken 的选项。

InteractiveBrowserCredentialInBrowserOptions

定义 InteractiveBrowserCredential 类的常用选项。

InteractiveBrowserCredentialNodeOptions

定义 InteractiveBrowserCredential 类的常用选项。

InteractiveCredentialOptions

需要用户交互的标识凭据的常见构造函数选项。

ManagedIdentityCredentialClientIdOptions

用于在 ManagedIdentityCredential 构造函数上发送的选项。 此变体支持 clientId 而不是 resourceId,因为两者只支持其中一个。

ManagedIdentityCredentialResourceIdOptions

用于在 ManagedIdentityCredential 构造函数上发送的选项。 此变体支持 resourceId 而不是 clientId,因为两者只支持其中一个。

MultiTenantTokenCredentialOptions

多租户应用程序的选项,允许其他允许的租户。

OnBehalfOfCredentialCertificateOptions

定义参数以使用证书对 OnBehalfOfCredential 进行身份验证。

OnBehalfOfCredentialSecretOptions

定义参数以使用机密对 OnBehalfOfCredential 进行身份验证。

TokenCachePersistenceOptions

在标识凭据中启用令牌缓存持久性的参数。

TokenCredential

表示能够提供身份验证令牌的凭据。

TokenCredentialOptions

提供用于配置标识库如何向Microsoft Entra ID发出身份验证请求的选项。

UsernamePasswordCredentialOptions

定义 UsernamePasswordCredential 类的选项。

VisualStudioCodeCredentialOptions

提供用于配置Visual Studio Code凭据的选项。

WorkloadIdentityCredentialOptions

WorkloadIdentityCredential 的选项

类型别名

BrokerOptions

在 InteractiveBrowserCredential 中启用 WAM 代理身份验证的参数。

BrowserLoginStyle

(仅限浏览器的功能) 身份验证流中使用的“登录样式”:

  • “重定向”会将用户重定向到身份验证页,然后在身份验证完成后将用户重定向回页面。
  • “弹出窗口”通过 打开一个新的浏览器窗口,并启动重定向流。 用户的现有浏览器窗口不会离开当前页
ClientCertificateCredentialPEMConfiguration

ClientCertificateCredential 的必需配置选项,包含 PEM 证书的字符串内容或 PEM 证书的路径。

DeviceCodePromptCallback

定义将传递给 DeviceCodeCredential 以便向用户显示身份验证详细信息的回调签名。

IdentityPlugin

Azure 标识插件的类型,一个接受插件上下文的函数。

OnBehalfOfCredentialOptions

OnBehalfOfCredential 类的可选参数。

枚举

AzureAuthorityHosts

已知 Azure 颁发机构主机的列表

函数

deserializeAuthenticationRecord(string)

将以前序列化的身份验证记录从字符串反序列化为 对象。

输入字符串必须包含以下属性:

  • “authority”
  • “homeAccountId”
  • “clientId”
  • “tenantId”
  • “username”
  • “version”

如果收到的版本不受支持,则会引发错误。

目前,唯一可用的版本是:“1.0”,在序列化身份验证记录时始终会设置该版本。

getDefaultAzureCredential()

返回 DefaultAzureCredential 的新实例。

serializeAuthenticationRecord(AuthenticationRecord)

AuthenticationRecord 序列化为字符串。

序列化身份验证记录的输出将包含以下属性:

  • “authority”
  • “homeAccountId”
  • “clientId”
  • “tenantId”
  • “username”
  • “version”

若要稍后将此字符串转换为序列化 AuthenticationRecord的 ,请使用导出的函数 deserializeAuthenticationRecord()

useIdentityPlugin(IdentityPlugin)

使用其他功能扩展 Azure 标识。 从插件包传递插件,例如:

  • @azure/identity-cache-persistence:提供永久性令牌缓存
  • @azure/identity-vscode:提供 的 VisualStudioCodeCredential 依赖项并启用它

例如:

import { cachePersistencePlugin } from "@azure/identity-cache-persistence";

import { useIdentityPlugin, DefaultAzureCredential } from "@azure/identity";
useIdentityPlugin(cachePersistencePlugin);

// The plugin has the capability to extend `DefaultAzureCredential` and to
// add middleware to the underlying credentials, such as persistence.
const credential = new DefaultAzureCredential({
  tokenCachePersistenceOptions: {
    enabled: true
  }
});

函数详细信息

deserializeAuthenticationRecord(string)

将以前序列化的身份验证记录从字符串反序列化为 对象。

输入字符串必须包含以下属性:

  • “authority”
  • “homeAccountId”
  • “clientId”
  • “tenantId”
  • “username”
  • “version”

如果收到的版本不受支持,则会引发错误。

目前,唯一可用的版本是:“1.0”,在序列化身份验证记录时始终会设置该版本。

function deserializeAuthenticationRecord(serializedRecord: string): AuthenticationRecord

参数

serializedRecord

string

以前序列化为字符串的身份验证记录。

返回

AuthenticationRecord。

getDefaultAzureCredential()

返回 DefaultAzureCredential 的新实例。

function getDefaultAzureCredential(): TokenCredential

返回

serializeAuthenticationRecord(AuthenticationRecord)

AuthenticationRecord 序列化为字符串。

序列化身份验证记录的输出将包含以下属性:

  • “authority”
  • “homeAccountId”
  • “clientId”
  • “tenantId”
  • “username”
  • “version”

若要稍后将此字符串转换为序列化 AuthenticationRecord的 ,请使用导出的函数 deserializeAuthenticationRecord()

function serializeAuthenticationRecord(record: AuthenticationRecord): string

参数

返回

string

useIdentityPlugin(IdentityPlugin)

使用其他功能扩展 Azure 标识。 从插件包传递插件,例如:

  • @azure/identity-cache-persistence:提供永久性令牌缓存
  • @azure/identity-vscode:提供 的 VisualStudioCodeCredential 依赖项并启用它

例如:

import { cachePersistencePlugin } from "@azure/identity-cache-persistence";

import { useIdentityPlugin, DefaultAzureCredential } from "@azure/identity";
useIdentityPlugin(cachePersistencePlugin);

// The plugin has the capability to extend `DefaultAzureCredential` and to
// add middleware to the underlying credentials, such as persistence.
const credential = new DefaultAzureCredential({
  tokenCachePersistenceOptions: {
    enabled: true
  }
});
function useIdentityPlugin(plugin: IdentityPlugin)

参数

plugin
IdentityPlugin

要注册的插件