> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/publish/site-audience/authenticated-access/setting-up-azure-ad.md).

# 设置 Azure AD

为你的文档访客设置 Azure AD 登录界面

{% hint style="warning" %}
本指南将带你设置文档的受保护登录页面。在阅读本指南之前，请先完成以下流程： [启用经过身份验证的访问](https://gitbook.com/docs/documentation/zh/publish/site-audience/authenticated-access/enabling-authenticated-access.md).
{% endhint %}

{% hint style="info" %}
Azure 集成存在一个已知限制：在身份验证后，标题 URL 片段会被移除。用户仍会进入正确页面，但会被带到页面顶部，而不是 URL 中指定的标题位置。一旦用户通过身份验证，在当前会话中就不会再出现这种行为，且会被定向到正确的标题。

这是由于 Microsoft 实施的一项安全措施。
{% endhint %}

### 概览

要使用 Azure AD 通过已验证访问来设置你的 GitBook 站点，流程如下：

{% stepper %}
{% step %}
[**在 Azure AD 中创建应用注册**](#id-1.-create-an-app-registration-in-azure-a-d)

在你的 Microsoft Entra ID 管理仪表板中创建一个 Azure AD 应用注册。
{% endstep %}

{% step %}
[**在你的网站上安装并配置 Azure AD 集成**](#id-2.-install-and-configure-the-azure-a-d-integration)

安装 Azure AD 集成，并向你的 GitBook 站点添加所需配置。
{% endstep %}

{% step %}
[**配置 Azure AD 以支持自适应内容（可选）**](#id-3.-configure-azure-a-d-for-adaptive-content-optional)

将你的 Azure AD 配置为与 GitBook 中的自适应内容配合使用。
{% endstep %}
{% endstepper %}

### 1. 在 Azure AD 中创建应用注册

首先在你的 Microsoft Entra ID 仪表板中创建一个应用注册。该应用注册将允许 GitBook Azure AD 集成请求令牌，以在向用户授予站点访问权限之前验证其身份。

1. 登录 Microsoft Entra ID 管理 [仪表板](https://entra.microsoft.com/).
2. 在左侧边栏中依次前往 **标识** > **应用程序** > **应用注册** 。
3. 点击 **+ 新注册，** 并为注册的应用命名。
4. 在 **支持的帐户类型** 下，选择“**仅此组织目录中的帐户（仅限默认目录 - 单租户）”**.
5. 暂时将重定向 URI 字段留空——你稍后需要填写。
6. 点击 **注册** 以完成应用注册。<br>

   <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-d792b2da26ce7e72515dc0e7454f30e3bab80285%2F25_04_10_azure_ad_integration_register_app.png?alt=media" alt="An Azure screenshot showing how to register an Azure AD app"><figcaption><p>为 GitBook VA 集成注册一个应用。</p></figcaption></figure>
7. 接下来，您应该会看到新注册应用的 **概述** 页面。复制并记下 **应用程序（客户端）ID** 和 **目录（租户）ID**.<br>

   <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-9e4a45be03c340e973c5caaa92070a499955287b%2F25_04_10_azure_ad_integration_app_reg_overview.png?alt=media" alt="An Azure screenshot showing the app registration overview"><figcaption><p>新创建的应用注册概览。</p></figcaption></figure>
8. 点击 **添加证书或机密**。随后应该会看到以下 **证书和机密** 页面：<br>

   <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-a3e1600c315de0d7549a0a4c85cc7e45dc4c59b4%2F25_04_10_azure_ad_integration_client_secrets.png?alt=media" alt="An Azure screenshot showing where to add a certificate or secret"><figcaption><p>添加证书或机密。</p></figcaption></figure>
9. 点击 **+ 新客户端机密**.
10. 输入合适的密钥描述，然后点击 **添加**.
11. 复制并记下该机密的 **值** 字段（***不是** 机密 ID*）。

### 2. 安装并配置 Azure AD 集成

创建好 Azure AD 应用注册后，下一步是在 GitBook 中安装 Azure AD 集成，并使用你之前生成的凭据将其与你的 Azure 应用关联：

1. 前往已 [启用经过身份验证的访问](https://gitbook.com/docs/documentation/zh/publish/site-audience/authenticated-access/enabling-authenticated-access.md#enable-authenticated-access) 并且希望使用 Azure AD 作为身份提供者的站点。
2. 点击站点设置右上角的 **集成** 按钮。<br>

   <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-36cf49e13fdd37a9c62aedf792e698c2451e34ba%2F25_04_10_va_site_integration_overview_screen.png?alt=media" alt="A GitBook screenshot showing the site settings overview"><figcaption></figcaption></figure>
3. 在侧边栏的类别中点击 **经过身份验证的访问** 。
4. 选择 **Azure** 集成。
5. 点击 **在此站点上安装**.<br>

   <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-b721d799f2ae94d5d247b6118a9cfe6c5ee5f555%2F25_04_10_azure_ad_install_on_site_screen.png?alt=media" alt="A GitBook screenshot showing installation of the Azure AD integration"><figcaption></figcaption></figure>
6. 在你的网站上安装该集成后，你应该会看到该集成的配置界面：<br>

   <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-ad94a4b9eff107036f35d03620e38615d43b9493%2F25_04_10_azure_ad_config_dialog.png?alt=media" alt="A GitBook screenshot showing the Azure AD configuration dialog"><figcaption></figcaption></figure>
7. 输入 **客户端 ID**, **租户 ID**和 **客户端密钥** 你在 [创建 Azure AD 应用注册](#id-1.-create-an-app-registration-in-azure-a-d) 后复制的值，然后点击“保存”。
8. 复制 **URL** 显示的 **对话框底部**.
9. 返回到你之前在 Microsoft Entra ID 仪表板中创建的 Azure AD 应用注册。
10. 前往 **管理** > **身份验证** （位于侧边栏中）。
11. 点击 **+ 添加平台** 并在打开的面板中选择 **Web** 卡片。<br>

    <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-785a4dd4a2d5e0994f0951d0c3eca13b9405d11f%2F25_04_10_azure_ad_app_reg_authentication.png?alt=media" alt="An Azure screenshot showing authentication platform settings"><figcaption></figcaption></figure>
12. 将 GitBook 集成 **URL** 粘贴到之前复制的 **重定向 URI** 字段中，然后点击“配置”。<br>

    <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-ca64e69ddb80de5149ea0453553d2136669c59cf%2F25_07_21_image.png?alt=media" alt="An Azure screenshot showing where to enter the redirect URI"><figcaption></figcaption></figure>
13. 返回 **Azure 集成** 安装页面 **（在 GitBook 中）**.
14. 关闭集成对话框，然后点击站点页面上的 **设置** 选项卡。
15. 前往 **受众** 并选择 **需要身份验证的访问** （如果尚未选中）。
16. 从 **Azure** 下拉菜单中选择 **身份验证后端** 部分中的选项。
17. 点击 **更新受众**.<br>

    <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-c73d425e06d977e52b03147cfea0ff4fe5bc9a0b%2F25_04_10_setting_up_azure_ad.png?alt=media" alt="A GitBook screenshot showing authenticated access settings"><figcaption></figcaption></figure>
18. 前往站点概览页面，然后点击 **发布** 如果该站点尚未发布。

现在，你的网站已在已验证访问保护下发布，并使用 Azure AD 作为身份提供程序。

要进行测试，请点击“访问”。系统会要求你使用 Azure 登录，这证实你的网站已通过 Azure 的已验证访问发布。

{% hint style="info" %}
在访问已发布内容 URL 并使用你的 Azure 凭据登录后，你可能会看到一个页面，提示你需要向管理员“请求批准”。你的管理员可以通过访问该已发布内容 URL、登录并代表组织批准来授予此请求。
{% endhint %}

### 3. 为自适应内容配置 Azure AD（可选）

要在启用了已验证访问的网站中利用自适应内容功能，请配置 Azure AD 应用注册，使其在身份验证令牌中将额外的用户信息作为声明包含进来。

这些以键值对表示的声明会传递给 GitBook，并可用于 [动态调整内容](https://gitbook.com/docs/documentation/zh/publish/adaptive-content/adapting-your-content.md) 以适应站点访客。

Azure AD 支持不同类型和级别的声明，每种声明都有各自的设置方式：

* **标准声明**：可能包含在令牌中，但默认情况下并非始终存在的常见声明。

{% hint style="info" %}
Azure AD 会优化令牌大小以提升性能。因此，许多声明 **不会** 默认包含在令牌中，必须由应用程序明确请求。若要确保包含 `email` , `groups` 或 `roles` 等声明，必须将其明确请求为 **可选声明**.
{% endhint %}

* **可选声明**：可为应用程序启用的其他预定义声明。
* **自定义声明**：源自 Azure AD 中的自定义用户属性，或通过自定义声明提供程序从外部系统获取的声明。

有关如何在 Azure AD 应用生成的令牌中包含这些不同类型声明的更多详细信息，请参阅以下 Microsoft Entra 文档指南：

* [用户属性](https://learn.microsoft.com/en-us/entra/external-id/customers/how-to-add-attributes-to-token)
* [可选声明](https://learn.microsoft.com/en-us/entra/identity-platform/optional-claims?toc=%2Fentra%2Fexternal-id%2Ftoc.json\&bc=%2Fentra%2Fexternal-id%2Fbreadcrumb%2Ftoc.json\&tabs=appui)
* [自定义声明](https://learn.microsoft.com/en-us/entra/identity-platform/custom-claims-provider-overview)

设置并配置要发送给 GitBook 的正确声明后，请前往“[调整内容](https://gitbook.com/docs/documentation/zh/publish/adaptive-content/adapting-your-content.md)”继续配置网站。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gitbook.com/docs/documentation/zh/publish/site-audience/authenticated-access/setting-up-azure-ad.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
