Share via


ManagedIdentityCredential class

嘗試使用部署環境中可用的受控識別進行驗證。 此驗證類型適用於 Azure VM、App Service 實例、Azure Functions 應用程式、Azure Kubernetes Services、Azure Service Fabric 實例和 Azure Cloud Shell 內部。

如需設定受控識別的詳細資訊,請參閱這裡: https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview

建構函式

ManagedIdentityCredential(ManagedIdentityCredentialClientIdOptions)

使用 clientId 建立 ManagedIdentityCredential 的實例

ManagedIdentityCredential(ManagedIdentityCredentialResourceIdOptions)

使用資源標識碼建立ManagedIdentityCredential的實例

ManagedIdentityCredential(string, TokenCredentialOptions)

使用 AKS Pod 身分識別) 時,使用使用者指派身分識別的用戶端識別碼,或應用程式註冊 (建立 ManagedIdentityCredential 的實例。

方法

getToken(string | string[], GetTokenOptions)

使用 Microsoft Entra ID 進行驗證,並在成功時傳回存取令牌。 如果驗證失敗,則會擲回 CredentialUnavailableError ,並包含失敗的詳細數據。 如果發生非預期的錯誤,將會擲回 AuthenticationError 並包含失敗的詳細數據。

建構函式詳細資料

ManagedIdentityCredential(ManagedIdentityCredentialClientIdOptions)

使用 clientId 建立 ManagedIdentityCredential 的實例

new ManagedIdentityCredential(options?: ManagedIdentityCredentialClientIdOptions)

參數

options
ManagedIdentityCredentialClientIdOptions

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

ManagedIdentityCredential(ManagedIdentityCredentialResourceIdOptions)

使用資源標識碼建立ManagedIdentityCredential的實例

new ManagedIdentityCredential(options?: ManagedIdentityCredentialResourceIdOptions)

參數

options
ManagedIdentityCredentialResourceIdOptions

設定發出存取令牌要求之資源的選項。

ManagedIdentityCredential(string, TokenCredentialOptions)

使用 AKS Pod 身分識別) 時,使用使用者指派身分識別的用戶端識別碼,或應用程式註冊 (建立 ManagedIdentityCredential 的實例。

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

參數

clientId

string

使用 AKS Pod 身分識別) 時,使用者指派身分識別的用戶端識別碼或應用程式註冊 (。

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>