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

ManagedIdentityCredential class

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

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

构造函数

ManagedIdentityCredential(ManagedIdentityCredentialClientIdOptions)

使用 clientId 创建 ManagedIdentityCredential 的实例

ManagedIdentityCredential(ManagedIdentityCredentialResourceIdOptions)

使用资源 ID 创建 ManagedIdentityCredential 的实例

ManagedIdentityCredential(string, TokenCredentialOptions)

使用用户分配的标识的客户端 ID 创建 ManagedIdentityCredential 实例,或使用 AKS pod-identity) 时,应用注册 (。

方法

getToken(string | string[], GetTokenOptions)

使用 Microsoft Entra ID 进行身份验证,如果成功,则返回访问令牌。 如果身份验证失败,则会引发 CredentialUnavailableError ,其中包含失败的详细信息。 如果发生意外错误,则会引发 AuthenticationError ,其中包含失败的详细信息。

构造函数详细信息

ManagedIdentityCredential(ManagedIdentityCredentialClientIdOptions)

使用 clientId 创建 ManagedIdentityCredential 的实例

new ManagedIdentityCredential(options?: ManagedIdentityCredentialClientIdOptions)

参数

options
ManagedIdentityCredentialClientIdOptions

用于配置发出访问令牌请求的客户端的选项。

ManagedIdentityCredential(ManagedIdentityCredentialResourceIdOptions)

使用资源 ID 创建 ManagedIdentityCredential 的实例

new ManagedIdentityCredential(options?: ManagedIdentityCredentialResourceIdOptions)

参数

options
ManagedIdentityCredentialResourceIdOptions

用于配置发出访问令牌请求的资源的选项。

ManagedIdentityCredential(string, TokenCredentialOptions)

使用用户分配的标识的客户端 ID 创建 ManagedIdentityCredential 实例,或使用 AKS pod-identity) 时,应用注册 (。

new ManagedIdentityCredential(clientId: string, options?: TokenCredentialOptions)

参数

clientId

string

使用 AKS pod-identity) 时,用户分配标识的客户端 ID 或应用注册 (。

options
TokenCredentialOptions

用于配置发出访问令牌请求的客户端的选项。

方法详细信息

getToken(string | string[], GetTokenOptions)

使用 Microsoft Entra ID 进行身份验证,如果成功,则返回访问令牌。 如果身份验证失败,则会引发 CredentialUnavailableError ,其中包含失败的详细信息。 如果发生意外错误,则会引发 AuthenticationError ,其中包含失败的详细信息。

function getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>

参数

scopes

string | string[]

令牌将有权访问的范围列表。

options
GetTokenOptions

用于配置此 TokenCredential 实现可能发出的任何请求的选项。

返回

Promise<AccessToken>