你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

适用于 JavaScript 的 Azure 核心身份验证客户端库 - 版本 1.10.1

@azure/core-auth 包提供了核心接口和帮助程序方法,用于使用 Azure Active Directory 和 Azure SDK 中常见的其他身份验证方案向 Azure 服务进行身份验证。 作为“核心”库,它不需要作为依赖项添加到任何用户代码,只需添加其他 Azure SDK 库。

入门指南

Installation

使用 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 文件夹以查看公共类的高级用法和行为。

Troubleshooting

如果您在使用此库时遇到问题,请随时 提出问题

Contributing

若要参与此库,请阅读 贡献指南 了解有关如何生成和测试代码的详细信息。