共用方式為


UsernamePasswordCredential class

警告

此 API 現已淘汰。

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

啟用驗證,以使用者的使用者名稱和密碼Microsoft Entra標識碼。 此認證需要高度信任,因此您只能在無法使用其他更安全的認證類型時使用它。

建構函式

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

使用使用者名稱和密碼,建立UsernamePasswordCredential的實例,其中包含針對 Microsoft Entra ID 進行驗證所需的詳細數據。

方法

getToken(string | string[], GetTokenOptions)

使用 Microsoft Entra 識別碼進行驗證,並在成功時傳回存取令牌。 如果驗證失敗,CredentialUnavailableError 將會擲回失敗的詳細數據。

如果使用者提供選項 disableAutomaticAuthentication,一旦無法以無訊息方式擷取令牌,此方法就不會嘗試要求用戶互動以擷取令牌。

建構函式詳細資料

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

使用使用者名稱和密碼,建立UsernamePasswordCredential的實例,其中包含針對 Microsoft Entra ID 進行驗證所需的詳細數據。

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

參數

tenantId

string

Microsoft Entra 租使用者 (directory) 。

clientId

string

租用戶中應用程式註冊的用戶端(應用程式)標識碼。

username

string

用戶帳戶的電子郵件地址(用戶名稱)。

password

string

用戶帳戶的帳戶密碼

options
UsernamePasswordCredentialOptions

設定發出驗證要求的客戶端的選項。

方法詳細資料

getToken(string | string[], GetTokenOptions)

使用 Microsoft Entra 識別碼進行驗證,並在成功時傳回存取令牌。 如果驗證失敗,CredentialUnavailableError 將會擲回失敗的詳細數據。

如果使用者提供選項 disableAutomaticAuthentication,一旦無法以無訊息方式擷取令牌,此方法就不會嘗試要求用戶互動以擷取令牌。

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

參數

scopes

string | string[]

令牌將具有存取權的範圍清單。

options
GetTokenOptions

用來設定此 TokenCredential 實作可能提出的任何要求的選項。

傳回

Promise<AccessToken>