Share via


@azure/identity package

類別

AggregateAuthenticationError

提供陣列,errors其中包含來自 ChainedTokenCredential 中認證之驗證失敗的 AuthenticationError 實例。

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

設定 AzureDeveloperCliCredential

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

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

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

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 ID。 如需如何設定用戶端密碼的詳細資訊,請參閱這裡:

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

啟用驗證以使用用戶可輸入https://microsoft.com/devicelogin的裝置代碼 Microsoft Entra ID。

EnvironmentCredential

啟用驗證以使用用戶端密碼或憑證 Microsoft Entra ID,或使用使用者名稱和密碼作為使用者。

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 ID。

UsernamePasswordCredential

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

VisualStudioCodeCredential

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

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

WorkloadIdentityCredential

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

介面

AccessToken

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

AuthenticationRecord

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

AuthenticationRequiredErrorOptions

AuthenticationRequiredError 的選擇性參數

AuthorityValidationOptions

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

AuthorizationCodeCredentialOptions

AuthorizationCodeCredential 的選項

AzureCliCredentialOptions

AzureCliCredential 的選項

AzureDeveloperCliCredentialOptions

AzureDeveloperCliCredential 的選項

AzurePowerShellCredentialOptions

AzurePowerShellCredential 的選項

BrokerAuthOptions

InteractiveBrowserCredential 的組態選項,以支援 WAM 訊息代理程序驗證。

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 ID。 定義 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

提供設定身分識別連結庫如何對 Microsoft Entra ID 進行驗證要求的選項。

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

要註冊的外掛程式