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

适用于 JavaScript 的 Azure HardwareSecurityModules 客户端库 - 版本 2.0.0

此包包含用于 Azure HardwareSecurityModules 客户端的同构 SDK(在 Node.js 和浏览器中运行)。

Azure 管理 API 提供了一组与硬件安全模块交互的 RESTful Web 服务。

Key links:

Getting started

当前支持的环境

See our support policy for more details.

Prerequisites

安装 @azure/arm-hardwaresecuritymodules

使用以下命令 npm安装适用于 JavaScript 的 Azure HardwareSecurityModules 客户端库:

npm install @azure/arm-hardwaresecuritymodules

创建和验证 AzureDedicatedHSMResourceProvider

要创建客户端对象以访问 Azure HardwareSecurityModules API,您需要 endpoint Azure HardwareSecurityModules 资源的 credential. Azure HardwareSecurityModules 客户端可以使用 Azure Active Directory 凭据进行身份验证。 You can find the endpoint for your Azure HardwareSecurityModules resource in the Azure Portal.

You can authenticate with Azure Active Directory using a credential from the @azure/identity library or an existing AAD Token.

To use the DefaultAzureCredential provider shown below, or other credential providers provided with the Azure SDK, please install the @azure/identity package:

npm install @azure/identity

还需要注册新的 AAD 应用程序,并通过向服务主体分配合适的角色来 授予对 Azure HardwareSecurityModules 的访问权限 (注意:诸如 "Owner" 此类的角色不会授予必要的权限)。

For more information about how to create an Azure AD Application check out this guide.

使用 Node.js 和类似 Node 的环境,可以使用 DefaultAzureCredential 类对客户端进行身份验证。

import { AzureHSMResourceProvider } from "@azure/arm-hardwaresecuritymodules";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new AzureHSMResourceProvider(new DefaultAzureCredential(), subscriptionId);

对于浏览器环境,请使用 InteractiveBrowserCredential 包中的 @azure/identity 进行身份验证。

import { InteractiveBrowserCredential } from "@azure/identity";
import { AzureHSMResourceProvider } from "@azure/arm-hardwaresecuritymodules";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const credential = new InteractiveBrowserCredential({
  tenantId: "<YOUR_TENANT_ID>",
  clientId: "<YOUR_CLIENT_ID>",
});
const client = new AzureHSMResourceProvider(credential, subscriptionId);

JavaScript Bundle

若要在浏览器中使用此客户端库,首先需要使用捆绑程序。 For details on how to do this, please refer to our bundling documentation.

Key concepts

AzureDedicatedHSMResourceProvider

AzureDedicatedHSMResourceProvider 是使用 Azure HardwareSecurityModules 客户端库的开发人员的主要接口。 探索此客户端对象上的方法,以了解可以访问的 Azure HardwareSecurityModules 服务的不同功能。

Troubleshooting

Logging

启用日志记录可能有助于发现有关故障的有用信息。 若要查看 HTTP 请求和响应的日志,请将 AZURE_LOG_LEVEL 环境变量设置为 info。 或者,可以在运行时通过调用 setLogLevel 中的 @azure/logger 来启用日志记录:

import { setLogLevel } from "@azure/logger";

setLogLevel("info");

有关如何启用日志的更详细说明,请查看 @azure/logger 包文档

Next steps

Please take a look at the samples directory for detailed examples on how to use this library.

Contributing

If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.