AuthorizationCodeCredential class

啟用透過授權碼流程取得的授權碼,對 Microsoft Entra ID 進行認證,詳情見 Microsoft Entra ID 文件:

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

建構函式

AuthorizationCodeCredential(string, string, string, string, AuthorizationCodeCredentialOptions)

建立一個 AuthorizationCodeCredential 實例,包含請求存取權杖所需細節,使用從 Microsoft Entra ID 取得的認證。

此認證的使用者目前必須起始授權碼流程,以取得要搭配此認證使用的授權碼。 這裡提供此流程的完整範例:

https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/v2/manual/authorizationCodeSample.ts

AuthorizationCodeCredential(string, string, string, string, string, AuthorizationCodeCredentialOptions)

建立一個 AuthorizationCodeCredential 實例,包含請求存取權杖所需細節,使用從 Microsoft Entra ID 取得的認證。

此認證的使用者目前必須起始授權碼流程,以取得要搭配此認證使用的授權碼。 這裡提供此流程的完整範例:

https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/v2/manual/authorizationCodeSample.ts

方法

getToken(string | string[], GetTokenOptions)

使用 Microsoft Entra ID 驗證,成功時回傳存取權杖。 如果驗證失敗,CredentialUnavailableError 將會擲回失敗的詳細數據。

建構函式詳細資料

AuthorizationCodeCredential(string, string, string, string, AuthorizationCodeCredentialOptions)

建立一個 AuthorizationCodeCredential 實例,包含請求存取權杖所需細節,使用從 Microsoft Entra ID 取得的認證。

此認證的使用者目前必須起始授權碼流程,以取得要搭配此認證使用的授權碼。 這裡提供此流程的完整範例:

https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/v2/manual/authorizationCodeSample.ts

new AuthorizationCodeCredential(tenantId: string, clientId: string, authorizationCode: string, redirectUri: string, options?: AuthorizationCodeCredentialOptions)

參數

tenantId

string

Microsoft Entra 租戶(目錄)的 ID 或名稱。 處理多租使用者案例時,可以使用「一般」。

clientId

string

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

authorizationCode

string

從下列授權碼流程接收的授權碼。 此授權碼不得已用來取得存取令牌。

redirectUri

string

用來要求授權碼的重新導向 URI。 必須是針對應用程式註冊設定的相同 URI。

options
AuthorizationCodeCredentialOptions

設定進行存取令牌要求之客戶端的選項。

AuthorizationCodeCredential(string, string, string, string, string, AuthorizationCodeCredentialOptions)

建立一個 AuthorizationCodeCredential 實例,包含請求存取權杖所需細節,使用從 Microsoft Entra ID 取得的認證。

此認證的使用者目前必須起始授權碼流程,以取得要搭配此認證使用的授權碼。 這裡提供此流程的完整範例:

https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/v2/manual/authorizationCodeSample.ts

new AuthorizationCodeCredential(tenantId: string, clientId: string, clientSecret: string, authorizationCode: string, redirectUri: string, options?: AuthorizationCodeCredentialOptions)

參數

tenantId

string

Microsoft Entra 租戶(目錄)的 ID 或名稱。 處理多租使用者案例時,可以使用「一般」。

clientId

string

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

clientSecret

string

針對應用程式註冊產生的客戶端密碼

authorizationCode

string

從下列授權碼流程接收的授權碼。 此授權碼不得已用來取得存取令牌。

redirectUri

string

用來要求授權碼的重新導向 URI。 必須是針對應用程式註冊設定的相同 URI。

options
AuthorizationCodeCredentialOptions

設定進行存取令牌要求之客戶端的選項。

方法詳細資料

getToken(string | string[], GetTokenOptions)

使用 Microsoft Entra ID 驗證,成功時回傳存取權杖。 如果驗證失敗,CredentialUnavailableError 將會擲回失敗的詳細數據。

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

參數

scopes

string | string[]

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

options
GetTokenOptions

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

傳回

Promise<AccessToken>