# @azure/graph 中文文档

规范地址：https://npmcn.com/package/%40azure/graph/

版本：5\.0\.3
npm 元数据更新时间：2026-03-19T20:32:31.767Z
中文译文更新时间：2026-11-07T13:57:15.723Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40azure/graph
原文对照：https://npmcn.com/package/%40azure/graph/?lang=original
项目主页：https://github.com/Azure/azure-sdk-for-js/tree/feature/v4/sdk/graphrbac/graph
源码仓库：https://github.com/Azure/azure-sdk-for-js

弃用说明：This package has been superseded by @microsoft/microsoft-graph-client

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1.3 MB，129 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：3 个
- 首次发布：2018-11-14T18:03:24.374Z
- 最新版本发布：2021-08-04T08:47:52.195Z
- 近 30 天下载量：42809（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 0 个）

## 中文简介

GraphRbac ManagementClient 库中含有节点.js和浏览器的打字类型定义.

## 安装

```sh
npm install @azure/graph
```

也可以使用：`pnpm add @azure/graph`、`yarn add @azure/graph`、`bun add @azure/graph`

## README

## 用于 JavaScript 的 Azure GraphRbac 管理客户端 SDK

> **3⁄4 ̄ ̧漯B**: 此软件包用于与 Azure Active 目录图 API 合作,该图已贬值并被替换为 [微软图形 API](https://developer.microsoft.com/graph). 从2022年6月30日起,使用 Azure AD Graph 的应用程序将不再收到 Azure Active Directory Graph 端点的回复.

帮助链接 :

-   [更新您的应用程序以使用 Microsoft 认证库和 Microsoft Graph API](https://techcommunity.microsoft.com/t5/azure-active-directory-identity/update-your-applications-to-use-microsoft-authentication-library/ba-p/1257363)
-   [应用程序迁移核对表](https://docs.microsoft.com/graph/migrate-azure-ad-graph-planning-checklist)
-   [@ microsoft/ microsoft-graph-客户端包](https://www.npmjs.com/package/@microsoft/microsoft-graph-client) 用于更新的微软图形 API

### 目前得到支持的环境

-   节点.js 6.x.x 或更高版本
-   浏览器 JavaScript

### 如何安装

```
npm install @azure/graph
```

### 如何使用

#### nodejs - 认证,客户端创建并获得签名的InUser,作为TypeScript所写的示例.

##### 安装 @ azure/ ms- rest- nodeaut

```
npm install @azure/ms-rest-nodeauth
```

##### 样本代码

```ts
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
import {
  GraphRbacManagementClient,
  GraphRbacManagementModels,
  GraphRbacManagementMappers
} from "@azure/graph";
const tenantId = "<Tenant_Id>";

msRestNodeAuth
  .interactiveLogin({
    tokenAudience: "https://graph.windows.net",
    domain: tenantId
  })
  .then((creds) => {
    const client = new GraphRbacManagementClient(creds, tenantId, {
      baseUri: "https://graph.windows.net"
    });
    client.signedInUser.get().then((result) => {
      console.log("The result is:");
      console.log(result);
    });
  })
  .catch((err) => {
    console.error(err);
  });
```

#### 浏览器 - 认证,客户端创建并获得签名的InUser作为JavaScript所写的示例.

##### 安装 @azure/ ms- rest- browseauth

```
npm install @azure/ms-rest-browserauth
```

##### 样本代码

见 [https://github.com/Azure/ms-rest-browserauth 页面存档备份,存于互联网档案馆](https://github.com/Azure/ms-rest-browserauth) 在浏览器中学习如何认证给Azure.

-   索引.html

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>@azure/graph sample</title>
    <script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
    <script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script>
    <script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
    <script src="node_modules/@azure/graph/dist/graph.js"></script>
    <script type="text/javascript">
      const tenantId = "<Tenant_Id>";
      const authManager = new msAuth.AuthManager({
        clientId: "<client id for your Azure AD app>",
        tenant: "<optional tenant for your organization>"
      });
      authManager.finalizeLogin().then((res) => {
        if (!res.isLoggedIn) {
          // may cause redirects
          authManager.login();
        }
        const client = new Azure.Graph.GraphRbacManagementClient(res.creds, tenantId, {
          baseUri: "https://graph.windows.net"
        });
        client.signedInUser
          .get()
          .then((result) => {
            console.log("The result is:");
            console.log(result);
          })
          .catch((err) => {
            console.log("An error occurred:");
            console.error(err);
          });
      });
    </script>
  </head>
  <body></body>
</html>
```

## 相关项目

-   [Microsoft Azure SDK 用于 Javascript](https://github.com/Azure/azure-sdk-for-js)

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fgraphrbac%2Fgraph%2FREADME.png)

## 常见问题

### @azure/graph 是什么？

GraphRbac ManagementClient 库中含有节点\.js和浏览器的打字类型定义\.注意：该包已被作者标记为弃用——This package has been superseded by @microsoft/microsoft-graph-client

### 如何安装 @azure/graph？

在项目目录运行 npm install @azure/graph，或使用 pnpm add / yarn add / bun add。

### @azure/graph 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @azure/graph 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @azure/graph 可以商用吗？

@azure/graph 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @azure/graph 的下载量有多少？

根据 npm 官方下载统计，@azure/graph 在 2026/10/08 – 2026/11/06 这 30 天内被下载 42,809 次，日均约 1,427 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @azure/graph 还在维护吗？

最新版本 5\.0\.3 发布于 2021/08/04（5 年前）；至今共发布 7 个版本，其中过去 12 个月发布了 0 个；首次发布于 2018/11/15。作者已将其标记为弃用，新项目建议寻找替代方案。

