套件 @azure/core-auth 提供核心介面和協助程式方法,以使用 Azure Active Directory 和 Azure SDK 中常見的其他驗證配置,向 Azure 服務進行驗證。 作為「核心」程式庫,它不需要新增為任何使用者程式碼的相依性,只需要新增其他 Azure SDK 程式庫。
入門指南
安裝
使用 npm 安裝此函式庫,如下所示
npm install @azure/core-auth
關鍵概念
介面代表 TokenCredential 能夠提供驗證權杖的認證。 套件包含 @azure/identity 實作 TokenCredential 介面的各種認證。
是 AzureKeyCredential 靜態金鑰型認證,支援透過方法進行 update 金鑰輪換。 當需要單一秘密值進行驗證時,例如使用共用存取金鑰時,請使用此選項。
這是 AzureNamedKeyCredential 以靜態名稱/金鑰為基礎的認證,可透過方法支援 update 名稱和金鑰輪替。 當同時需要秘密值和標籤時,例如使用共用存取金鑰和共用存取金鑰名稱時,請使用此選項。
是 AzureSASCredential 靜態簽章型認證,支援透過方法更新 update 簽章值。 使用共用存取簽章時,請使用此選項。
範例
AzureKeyCredential
import { AzureKeyCredential } from "@azure/core-auth";
const credential = new AzureKeyCredential("secret value");
console.log(credential.key); // prints: "secret value"
credential.update("other secret value");
console.log(credential.key); // prints: "other secret value"
AzureNamedKeyCredential
import { AzureNamedKeyCredential } from "@azure/core-auth";
const credential = new AzureNamedKeyCredential("ManagedPolicy", "secret value");
console.log(`${credential.name}, ${credential.key}`); // prints: "ManagedPolicy, secret value"
credential.update("OtherManagedPolicy", "other secret value");
console.log(`${credential.name}, ${credential.key}`); // prints: "OtherManagedPolicy, other secret value"
AzureSASCredential
import { AzureSASCredential } from "@azure/core-auth";
const credential = new AzureSASCredential("signature1");
console.log(credential.signature); // prints: "signature1"
credential.update("signature2");
console.log(credential.signature); // prints: "signature2"
後續步驟
您可以執行 npm run test在本機建置和執行測試。 探索 test 資料夾以查看公用類別的進階使用方式和行為。
故障排除
如果您在使用此庫時遇到問題,請隨時 提出問題。
Contributing
如果您想要參與此連結庫,請閱讀 參與指南,以深入瞭解如何建置和測試程序代碼。