共用方式為


@azure/identity package

類別

AggregateAuthenticationError

提供 errors 陣列,其中包含 AuthenticationError 實例,以從 ChainedTokenCredential中的認證進行驗證失敗。

AuthenticationError

提供有關無法向 Azure Active Directory 進行驗證的詳細數據。 [errorResponse] 欄位包含特定失敗的詳細數據。

AuthenticationRequiredError

嘗試以無訊息方式擷取令牌之後,用來強制執行驗證的錯誤。

AuthorizationCodeCredential

使用透過授權碼流程取得的授權碼,啟用驗證以Microsoft Entra ID,如Microsoft Entra ID 檔所述:

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

AzureCliCredential

此認證會透過 Azure CLI ('az') 命令行工具,使用目前登入的使用者登入資訊。 若要這樣做,它會讀取使用者存取令牌,並使用 Azure CLI 命令 “az account get-access-token” 到期時間。

AzureDeveloperCliCredential

Azure 開發人員 CLI 是命令行介面工具,可讓開發人員在 Azure 中建立、管理及部署資源。 其建置在 Azure CLI 之上,並提供 Azure 開發人員專屬的其他功能。 它可讓使用者以使用者和/或服務主體的身分,針對 Microsoft Entra ID進行驗證。 AzureDeveloperCliCredential 會在開發環境中進行驗證,並代表 Azure 開發人員 CLI 中的登入使用者或服務主體取得令牌。 其會作為 Azure 開發人員 CLI 登入使用者或服務主體,並在下方執行 Azure CLI 命令,以針對 Microsoft Entra ID 驗證應用程式。

設定 AzureDeveloperCliCredential

若要使用此認證,開發人員必須使用下列其中一個命令,在 Azure 開發人員 CLI 中本機進行驗證:

  1. 在 Azure 開發人員 CLI 中執行 「azd auth login」,以以使用者身分以互動方式進行驗證。
  2. 執行 “azd auth login --client-id clientID --client-secret clientSecret --tenant-id tenantID”,以作為服務主體進行驗證。

視組織中的重新整理令牌有效性而定,您可能需要在特定時間週期之後重複此程式。 一般而言,重新整理令牌有效期間是數周到幾個月。 AzureDeveloperCliCredential 會提示您再次登入。

AzurePipelinesCredential

此認證的設計目的是在 Azure Pipelines 中搭配服務連線作為工作負載身分識別同盟的設定。

AzurePowerShellCredential

此認證將使用 Azure PowerShell 模組中目前登入的用戶資訊。 若要這樣做,它會讀取使用者存取令牌,並使用 Azure PowerShell 命令過期時間 Get-AzAccessToken -ResourceUrl {ResourceScope}

ChainedTokenCredential

允許嘗試多個 TokenCredential 實作,直到其中一個 getToken 方法傳回存取令牌為止。

ClientAssertionCredential

使用 JWT 判斷提示驗證服務主體。

ClientCertificateCredential

使用指派給應用程式註冊的 PEM 編碼憑證,啟用驗證以Microsoft Entra ID。 如需如何設定憑證驗證的詳細資訊,請參閱這裡:

https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-certificate-credentials#register-your-certificate-with-azure-ad

ClientSecretCredential

使用針對應用程式註冊產生的用戶端密碼,啟用驗證以Microsoft Entra標識符。 如需如何設定用戶端密碼的詳細資訊,請參閱這裡:

https://learn.microsoft.com/entra/identity-platform/quickstart-configure-app-access-web-apis#add-credentials-to-your-web-application

CredentialUnavailableError

這表示在鏈結認證中嘗試的認證無法當做認證使用。 它不會將此視為應該停止鏈結的錯誤,而是攔截並持續鏈結

DefaultAzureCredential

提供預設 ChainedTokenCredential 組態,適用於大部分使用 Azure SDK 的應用程式。

DeviceCodeCredential

開啟驗證,以使用使用者可以輸入的裝置代碼來Microsoft Entra 識別碼 https://microsoft.com/devicelogin

EnvironmentCredential

啟用驗證,以使用用戶端密碼或憑證,或作為使用者名稱和密碼的使用者,來Microsoft Entra 標識符。

InteractiveBrowserCredential

啟用驗證,以使用互動式登入流程在網頁瀏覽器內Microsoft Entra ID。

ManagedIdentityCredential

嘗試使用部署環境中可用的受控識別進行驗證。 此驗證類型適用於 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

OnBehalfOfCredential

使用 代表流程啟用驗證,以Microsoft Entra 標識符。

UsernamePasswordCredential

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

VisualStudioCodeCredential

使用 VSCode 擴充功能 「Azure 帳戶」所提供的認證連線到 Azure。 一旦使用者透過延伸模組登入,此認證就可以共用延伸模組快取的相同重新整理令牌。

這是 已知問題, 此認證不適用於 Azure 帳戶擴充功能 版本,0.9.11。 此問題的長期修正正在進行中。 同時,請考慮使用 AzureCliCredential進行驗證。

WorkloadIdentityCredential

工作負載身分識別驗證是 Azure 中的一項功能,可讓在虛擬機 (VM) 上執行的應用程式存取其他 Azure 資源,而不需要服務主體或受控識別。 使用工作負載身分識別驗證,應用程式會使用自己的身分識別自行驗證,而不是使用共用服務主體或受控識別。 在幕後,工作負載身分識別驗證會使用服務帳戶認證(SAC)的概念,Azure 會自動建立並安全地儲存在 VM 中。 藉由使用工作負載身分識別驗證,您可以避免需要針對每個 VM 上的每個應用程式管理和輪替服務主體或受控識別。 此外,由於 SAC 是由 Azure 自動建立和管理,因此您不需要擔心儲存和保護敏感性認證本身。 WorkloadIdentityCredential 支援在 Azure Kubernetes 上Microsoft Entra Workload ID 驗證,並使用 Azure Kubernetes 環境中可用的 SA 來取得令牌。 如需詳細資訊,請參閱 Microsoft Entra Workload ID

介面

AccessToken

表示到期時間的存取令牌。

AuthenticationRecord

用來在快取中尋找快取令牌的記錄。

AuthenticationRequiredErrorOptions

AuthenticationRequiredError 的選擇性參數

AuthorityValidationOptions

提供選項,以設定身分識別連結庫在驗證要求期間如何進行授權驗證,以Microsoft Entra ID。

AuthorizationCodeCredentialOptions

AuthorizationCodeCredential 的選項

AzureCliCredentialOptions

AzureCliCredential 的選項

AzureDeveloperCliCredentialOptions

AzureDeveloperCliCredential 的選項

AzurePipelinesCredentialOptions

AzurePipelinesCredential 類別的選擇性參數。

AzurePowerShellCredentialOptions

AzurePowerShellCredential 的選項

BrokerAuthOptions

InteractiveBrowserCredential 以支援 WAM Broker 驗證的組態選項。

BrokerDisabledOptions

停用 WAM 訊息代理程式驗證時的參數。

BrokerEnabledOptions

啟用 WAM 訊息代理程式驗證時的參數。

BrowserCustomizationOptions

瀏覽器自定義的共享組態選項

ClientAssertionCredentialOptions

ClientAssertionCredential 的選項

ClientCertificateCredentialOptions

ClientCertificateCredential 類別的選擇性參數。

ClientCertificatePEMCertificate

ClientCertificateCredential的必要組態選項,以及 PEM 憑證的字串內容

ClientCertificatePEMCertificatePath

ClientCertificateCredential的必要組態選項,以及 PEM 憑證的路徑。

ClientSecretCredentialOptions

ClientSecretCredential 類別的選擇性參數。

CredentialPersistenceOptions

支援永續性令牌快取之認證的共享組態選項。

DefaultAzureCredentialClientIdOptions

提供選項來設定 DefaultAzureCredential 類別。 這個變化支援 managedIdentityClientId,而不是 managedIdentityResourceId,因為只支援其中一個。

DefaultAzureCredentialOptions

提供選項來設定 DefaultAzureCredential 類別。

DefaultAzureCredentialResourceIdOptions

提供選項來設定 DefaultAzureCredential 類別。 這個變化支援 managedIdentityResourceId,而不是 managedIdentityClientId,因為只支援其中一個。

DeviceCodeCredentialOptions

定義 Node.js的 InteractiveBrowserCredential 類別選項。

DeviceCodeInfo

提供必須輸入程式代碼的用戶代碼和驗證 URI。 也提供訊息,向用戶顯示,其中包含這些詳細數據的指示。

EnvironmentCredentialOptions

根據可用的環境變數,啟用驗證以Microsoft Entra標識符。 定義 EnvironmentCredential 類別的選項。

ErrorResponse

如需詳細資訊,請參閱官方檔:

https://learn.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-oauth-code#error-response-1

注意:本檔適用於 v1 OAuth 支援,但相同的錯誤回應詳細數據仍適用於 v2。

GetBearerTokenProviderOptions

設定令牌提供者的選項。

GetTokenOptions

定義 TokenCredential.getToken 的選項。

InteractiveBrowserCredentialInBrowserOptions

定義 InteractiveBrowserCredential 類別的通用選項。

InteractiveBrowserCredentialNodeOptions

定義 InteractiveBrowserCredential 類別的通用選項。

InteractiveCredentialOptions

需要用戶互動之身分識別認證的常見建構函式選項。

ManagedIdentityCredentialClientIdOptions

在managedIdentityCredential 建構函式 上傳送的選項。 這個變化支援 clientId,而不是 resourceId,因為只支援其中一個。

ManagedIdentityCredentialResourceIdOptions

在managedIdentityCredential 建構函式 上傳送的選項。 這個變化支援 resourceId,而不是 clientId,因為只支援其中一個。

MultiTenantTokenCredentialOptions

允許額外允許租使用者之多租使用者應用程式的選項。

OnBehalfOfCredentialCertificateOptions

定義參數,以使用憑證驗證 OnBehalfOfCredential

OnBehalfOfCredentialSecretOptions

定義參數,以使用秘密驗證 OnBehalfOfCredential

TokenCachePersistenceOptions

在身分識別認證中啟用令牌快取持續性的參數。

TokenCredential

表示能夠提供驗證令牌的認證。

TokenCredentialOptions

提供選項,以設定身分識別連結庫如何向 entra ID Microsoft提出驗證要求。

UsernamePasswordCredentialOptions

定義 UsernamePasswordCredential 類別的選項。

VisualStudioCodeCredentialOptions

提供設定 Visual Studio Code 認證的選項。

WorkloadIdentityCredentialOptions

WorkloadIdentityCredential 的選項

類型別名

BrokerOptions

在 InteractiveBrowserCredential 中啟用 WAM 訊息代理程式驗證的參數。

BrowserLoginStyle

(僅限瀏覽器功能)在驗證流程中使用的「登入樣式」:

  • 「重新導向」會將使用者重新導向至驗證頁面,然後在驗證完成後將其重新導向回頁面。
  • 「快顯」會透過重新導向流程起始新的瀏覽器視窗。 用戶現有的瀏覽器視窗不會離開目前的頁面
ClientCertificateCredentialPEMConfiguration

ClientCertificateCredential的必要組態選項,包含 PEM 憑證的字串內容或 PEM 憑證的路徑。

DeviceCodePromptCallback

定義將傳遞至 DeviceCodeCredential 的回呼簽章,以便向使用者顯示驗證詳細數據。

IdentityPlugin

Azure 身分識別外掛程式的類型,這是接受外掛程式內容的函式。

OnBehalfOfCredentialOptions

OnBehalfOfCredential 類別的選擇性參數。

列舉

AzureAuthorityHosts

已知 Azure 授權單位主機的清單

函數

deserializeAuthenticationRecord(string)

將先前串行化的驗證記錄從字串還原串行化為物件。

輸入字串必須包含下列屬性:

  • “authority”
  • “homeAccountId”
  • “clientId”
  • “tenantId”
  • “username”
  • “version”

如果不支持我們收到的版本,將會擲回錯誤。

目前唯一可用的版本是:“1.0”,一律會在串行化驗證記錄時設定。

getBearerTokenProvider(TokenCredential, string | string[], GetBearerTokenProviderOptions)

傳回提供持有人令牌的回呼。 例如,持有人令牌可用來驗證要求,如下所示:

import { DefaultAzureCredential } from "@azure/identity";

const credential = new DefaultAzureCredential();
const scope = "https://cognitiveservices.azure.com/.default";
const getAccessToken = getBearerTokenProvider(credential, scope);
const token = await getAccessToken();

// usage
const request = createPipelineRequest({ url: "https://example.com" });
request.headers.set("Authorization", `Bearer ${token}`);
getDefaultAzureCredential()

傳回 DefaultAzureCredential的新實例。

serializeAuthenticationRecord(AuthenticationRecord)

AuthenticationRecord 串行化為字串。

序列化驗證記錄的輸出將包含下列屬性:

  • “authority”
  • “homeAccountId”
  • “clientId”
  • “tenantId”
  • “username”
  • “version”

若要稍後將此字串轉換成串列化 AuthenticationRecord,請使用匯出的函式 deserializeAuthenticationRecord()

useIdentityPlugin(IdentityPlugin)

使用其他功能擴充 Azure 身分識別。 從外掛程式套件傳遞外掛程式,例如:

  • @azure/identity-cache-persistence:提供持續性令牌快取
  • @azure/identity-vscode:提供 VisualStudioCodeCredential 的相依性,並加以啟用

例:

import { cachePersistencePlugin } from "@azure/identity-cache-persistence";

import { useIdentityPlugin, DefaultAzureCredential } from "@azure/identity";
useIdentityPlugin(cachePersistencePlugin);

// The plugin has the capability to extend `DefaultAzureCredential` and to
// add middleware to the underlying credentials, such as persistence.
const credential = new DefaultAzureCredential({
  tokenCachePersistenceOptions: {
    enabled: true
  }
});

函式詳細資料

deserializeAuthenticationRecord(string)

將先前串行化的驗證記錄從字串還原串行化為物件。

輸入字串必須包含下列屬性:

  • “authority”
  • “homeAccountId”
  • “clientId”
  • “tenantId”
  • “username”
  • “version”

如果不支持我們收到的版本,將會擲回錯誤。

目前唯一可用的版本是:“1.0”,一律會在串行化驗證記錄時設定。

function deserializeAuthenticationRecord(serializedRecord: string): AuthenticationRecord

參數

serializedRecord

string

先前串行化為字串的驗證記錄。

傳回

AuthenticationRecord。

getBearerTokenProvider(TokenCredential, string | string[], GetBearerTokenProviderOptions)

傳回提供持有人令牌的回呼。 例如,持有人令牌可用來驗證要求,如下所示:

import { DefaultAzureCredential } from "@azure/identity";

const credential = new DefaultAzureCredential();
const scope = "https://cognitiveservices.azure.com/.default";
const getAccessToken = getBearerTokenProvider(credential, scope);
const token = await getAccessToken();

// usage
const request = createPipelineRequest({ url: "https://example.com" });
request.headers.set("Authorization", `Bearer ${token}`);
function getBearerTokenProvider(credential: TokenCredential, scopes: string | string[], options?: GetBearerTokenProviderOptions): () => Promise<string>

參數

credential
TokenCredential

用來驗證要求的認證。

scopes

string | string[]

持有人令牌所需的範圍。

options
GetBearerTokenProviderOptions

設定令牌提供者的選項。

傳回

() => Promise<string>

提供持有人令牌的回呼。

getDefaultAzureCredential()

傳回 DefaultAzureCredential的新實例。

function getDefaultAzureCredential(): TokenCredential

傳回

serializeAuthenticationRecord(AuthenticationRecord)

AuthenticationRecord 串行化為字串。

序列化驗證記錄的輸出將包含下列屬性:

  • “authority”
  • “homeAccountId”
  • “clientId”
  • “tenantId”
  • “username”
  • “version”

若要稍後將此字串轉換成串列化 AuthenticationRecord,請使用匯出的函式 deserializeAuthenticationRecord()

function serializeAuthenticationRecord(record: AuthenticationRecord): string

參數

傳回

string

useIdentityPlugin(IdentityPlugin)

使用其他功能擴充 Azure 身分識別。 從外掛程式套件傳遞外掛程式,例如:

  • @azure/identity-cache-persistence:提供持續性令牌快取
  • @azure/identity-vscode:提供 VisualStudioCodeCredential 的相依性,並加以啟用

例:

import { cachePersistencePlugin } from "@azure/identity-cache-persistence";

import { useIdentityPlugin, DefaultAzureCredential } from "@azure/identity";
useIdentityPlugin(cachePersistencePlugin);

// The plugin has the capability to extend `DefaultAzureCredential` and to
// add middleware to the underlying credentials, such as persistence.
const credential = new DefaultAzureCredential({
  tokenCachePersistenceOptions: {
    enabled: true
  }
});
function useIdentityPlugin(plugin: IdentityPlugin)

參數

plugin
IdentityPlugin

要註冊的外掛程式