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

UsernamePasswordCredential class

警告

现已弃用此 API。

UsernamePasswordCredential is deprecated. Use a more secure credential. See https://aka.ms/azsdk/identity/mfa for details.

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

构造函数

UsernamePasswordCredential(string, string, string, string, UsernamePasswordCredentialOptions)

使用用户名和密码针对 Microsoft Entra ID 进行身份验证所需的详细信息创建 UsernamePasswordCredential 的实例。

方法

getToken(string | string[], GetTokenOptions)

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

如果用户提供了 disableAutomaticAuthentication选项,则一旦无法以无提示方式检索令牌,此方法将不会尝试请求用户交互以检索令牌。

构造函数详细信息

UsernamePasswordCredential(string, string, string, string, UsernamePasswordCredentialOptions)

使用用户名和密码针对 Microsoft Entra ID 进行身份验证所需的详细信息创建 UsernamePasswordCredential 的实例。

new UsernamePasswordCredential(tenantId: string, clientId: string, username: string, password: string, options?: UsernamePasswordCredentialOptions)

参数

tenantId

string

Microsoft Entra 租户(目录)。

clientId

string

租户中应用注册的客户端(应用程序)ID。

username

string

用户帐户的电子邮件地址(用户名)。

password

string

用户帐户的帐户密码

options
UsernamePasswordCredentialOptions

用于配置发出身份验证请求的客户端的选项。

方法详细信息

getToken(string | string[], GetTokenOptions)

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

如果用户提供了 disableAutomaticAuthentication选项,则一旦无法以无提示方式检索令牌,此方法将不会尝试请求用户交互以检索令牌。

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

参数

scopes

string | string[]

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

options
GetTokenOptions

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

返回

Promise<AccessToken>