> 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/fa-bu/site-audience/authenticated-access/setting-up-auth0.md).

# 设置 Auth0

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

{% hint style="info" %}
前往我们的指南，找到一个 [完整操作指南](https://gitbook.com/docs/guides/docs-personalization-and-authentication/how-to-personalize-your-gitbook-site-using-auth0-and-adaptive-content) 关于使用 Auth0 设置经过身份验证的访问和自适应内容。
{% endhint %}

{% hint style="warning" %}
本指南将带你为你的文档设置一个受保护的登录界面。在开始本指南之前，请确保你已经先阅读过 [启用已认证访问](/docs/documentation/zh/fa-bu/site-audience/authenticated-access/enabling-authenticated-access.md).
{% endhint %}

要使用 Auth0 为你的 GitBook 站点设置经过身份验证的访问，流程如下：

{% stepper %}
{% step %}
[**在 Auth0 中创建一个新应用**](#id-1.-create-a-new-application-in-auth0)

在你的 Auth0 仪表板中创建一个 Auth0 应用。
{% endstep %}

{% step %}
[**安装并配置 Auth0 集成**](#id-2.-install-and-configure-the-auth0-integration)

安装 Auth0 集成，并将所需配置添加到你的 GitBook 站点。
{% endstep %}

{% step %}
[**为自适应内容配置 Auth0（可选）**](#id-3.-configure-auth0-for-adaptive-content-optional)

配置 Auth0 以便在 GitBook 中配合自适应内容使用。
{% endstep %}
{% endstepper %}

### 1. 在 Auth0 中创建一个新应用

首先在你的 Auth0 平台仪表板中创建一个新应用。此应用将允许 GitBook Auth0 集成在授予用户访问你的网站之前请求令牌以验证用户身份。

1. 登录你的 Auth0 [仪表板](https://manage.auth0.com/dashboard/).
2. 前往 **应用程序 > 应用程序** 部分。
3. 点击 **+ 创建应用** 按钮，并为你的应用命名。
4. 在 **选择应用类型，** 选择 **常规 Web 应用**.
5. 在 **快速入门** 在新创建应用的界面中，选择 **Node.js（Express）** 然后 **我想集成我的应用**.
6. 然后你会看到如下所示的配置界面。\
   点击 **保存设置并继续**.<br>

   <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2FHoIpHTIRmkCvhw1kBVZZ%2Fauth0_app_configure_screen.png?alt=media&amp;token=ef189183-2547-4e5e-b22f-2d3169f2b600" alt=""><figcaption></figcaption></figure>
7. 点击 **设置** 选项卡。
8. 复制并记下 **域名**, **客户端 ID** 以及 **客户端机密**.

{% hint style="warning" %}
请确保你已 **启用了至少一个连接** 适用于你的 Auth0 应用，位于 **连接** 选项卡。
{% endhint %}

### 2. 安装并配置 Auth0 集成

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

1. 前往你已启用经过身份验证访问并希望将 Auth0 作为身份提供方的网站。
2. 点击 **集成** 按钮，位于站点设置右上角。<br>

   <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2FgBMsbydNsuqx7eqcz0JN%2Fva_site_integration_overview_screen.png?alt=media&amp;token=ead70cf3-93cf-4aef-b77a-321afad38900" alt=""><figcaption></figcaption></figure>
3. 点击 **已认证访问** ，从侧边栏的类别中。
4. 选择 **Auth0** 集成。
5. 点击 **安装到此站点**.<br>

   <figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2F98d9Svq3PBdpaiRuyV14%2Fauth0_install_integration.png?alt=media&amp;token=155beba6-bc85-42c6-acb8-18f782f207a4" alt=""><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%2FGpdmoJqOQvrwFBaQ17Gv%2Fauth0_configure_integration.png?alt=media&amp;token=61bc203c-2553-453f-b701-176264af044b" alt=""><figcaption></figcaption></figure>
7. 输入 **域名**, **客户端 ID** 以及 **客户端机密** 你之前创建 Auth0 应用后复制的值。对于 Auth0 域名，请输入从 Auth0 复制的域名（请确保在其前面加上 `https://`).
8. **（可选）** 启用 **在 JWT 令牌中包含声明** 选项（位于对话框底部），如果你已为你的网站启用 [自适应内容](/docs/documentation/zh/fa-bu/adaptive-content/enabling-adaptive-content.md).
9. 复制并记下 **回调** **URL** ，它显示在 **对话框底部**.
10. 点击 **保存**.
11. 返回你之前在 Auth0 仪表板中创建的 Auth0 应用。
12. 浏览到 **应用程序 > 应用程序** 在侧边栏中，并选择 **设置** 选项卡。
13. 向下滚动到 **应用 URI** 设置部分
14. 将 **回调 URL** 你之前从 GitBook 集成对话框复制的内容粘贴到 **允许的回调 URL** 输入框。
15. 点击 **保存。**
16. 返回到 **Auth0 集成** 安装页面 **在 GitBook 中**.
17. 关闭集成对话框，然后点击站点页面中的 **设置** 选项卡。
18. 浏览到 **受众** 并选择 **经过身份验证的访问** （如果尚未选择）。
19. 选择 **Auth0** 从下拉菜单中 **身份验证后端** 部分。
20. 点击 **更新受众**.
21. 前往站点概览页面，然后点击 **发布** 如果站点尚未发布。

你的网站现在已通过身份验证访问发布，并使用你的 Auth0 作为身份提供方。

要进行测试，请点击 **访问**。系统会要求你使用 Auth0 登录，这将确认你的网站已通过 Auth0 的身份验证访问发布。

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

{% embed url="<https://www.youtube.com/embed/uhWeQkgyg8Y?si=7_kD3RF-Is_MnYhZ>" %}

要在你的经过身份验证访问的网站中利用自适应内容功能， [配置 Auth0 应用](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims) 以便将额外的用户信息作为声明包含在身份验证令牌中。

这些声明以键值对的形式传递给 GitBook，可用于 [自适应内容](/docs/documentation/zh/fa-bu/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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/fa-bu/site-audience/authenticated-access/setting-up-auth0.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
