共用方式為


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)

使用從 Microsoft entra ID 取得的驗證,建立 AuthorizationCodeCredential 實例,其中包含要求存取令牌所需的詳細數據。

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

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)

使用從 Microsoft entra ID 取得的驗證,建立 AuthorizationCodeCredential 實例,其中包含要求存取令牌所需的詳細數據。

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

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

方法

getToken(string | string[], GetTokenOptions)

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

建構函式詳細資料

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

使用從 Microsoft entra ID 取得的驗證,建立 AuthorizationCodeCredential 實例,其中包含要求存取令牌所需的詳細數據。

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

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 租使用者(目錄)標識碼或名稱。 處理多租使用者案例時,可以使用「一般」。

clientId

string

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

authorizationCode

string

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

redirectUri

string

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

options
AuthorizationCodeCredentialOptions

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

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

使用從 Microsoft entra ID 取得的驗證,建立 AuthorizationCodeCredential 實例,其中包含要求存取令牌所需的詳細數據。

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

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 租使用者(目錄)標識碼或名稱。 處理多租使用者案例時,可以使用「一般」。

clientId

string

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

clientSecret

string

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

authorizationCode

string

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

redirectUri

string

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

options
AuthorizationCodeCredentialOptions

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

方法詳細資料

getToken(string | string[], GetTokenOptions)

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

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

參數

scopes

string | string[]

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

options
GetTokenOptions

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

傳回

Promise<AccessToken>