你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
此包包含用于 Azure ManagedServiceIdentity 客户端的同构 SDK(在 Node.js 和浏览器中运行)。
托管服务标识客户端。
Source code | Package (NPM) | API reference documentation | Samples
Getting started
当前支持的环境
- LTS 版本的 Node.js
- 最新版本的 Safari、Chrome、Edge 和 Firefox。
See our support policy for more details.
Prerequisites
安装 @azure/arm-msi
包
使用以下命令安装 npm
适用于 JavaScript 的 Azure ManagedServiceIdentity 客户端库:
npm install @azure/arm-msi
创建和验证 ManagedServiceIdentityClient
若要创建客户端对象以访问 Azure ManagedServiceIdentity API,需要 Azure ManagedServiceIdentity 资源credential
的 和 endpoint
. Azure ManagedServiceIdentity 客户端可以使用 Azure Active Directory 凭据进行身份验证。
You can find the endpoint for your Azure ManagedServiceIdentity 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 ManagedServiceIdentity 的访问权限 (注意:诸如 "Owner"
此类的角色不会授予必要的权限)。
For more information about how to create an Azure AD Application check out this guide.
使用 Node.js 和类似 Node 的环境,可以使用 DefaultAzureCredential
类对客户端进行身份验证。
import { ManagedServiceIdentityClient } from "@azure/arm-msi";
import { DefaultAzureCredential } from "@azure/identity";
const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new ManagedServiceIdentityClient(new DefaultAzureCredential(), subscriptionId);
对于浏览器环境,请使用 InteractiveBrowserCredential
包中的 @azure/identity
进行身份验证。
import { InteractiveBrowserCredential } from "@azure/identity";
import { ManagedServiceIdentityClient } from "@azure/arm-msi";
const subscriptionId = "00000000-0000-0000-0000-000000000000";
const credential = new InteractiveBrowserCredential({
tenantId: "<YOUR_TENANT_ID>",
clientId: "<YOUR_CLIENT_ID>",
});
const client = new ManagedServiceIdentityClient(credential, subscriptionId);
JavaScript Bundle
若要在浏览器中使用此客户端库,首先需要使用捆绑程序。 For details on how to do this, please refer to our bundling documentation.
Key concepts
ManagedServiceIdentityClient
ManagedServiceIdentityClient
是使用 Azure ManagedServiceIdentity 客户端库的开发人员的主要接口。 浏览此客户端对象上的方法,了解可以访问的 Azure ManagedServiceIdentity 服务的不同功能。
Troubleshooting
Logging
启用日志记录可能有助于发现有关故障的有用信息。 若要查看 HTTP 请求和响应的日志,请将 AZURE_LOG_LEVEL
环境变量设置为 info
。 或者,可以通过在运行时调用 setLogLevel
以下项 @azure/logger
来启用日志记录:
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
有关如何启用日志的更详细说明,可以查看 @azure/记录器包文档。
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.