> 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

{% hint style="info" %}
前往我们的指南以找到 [完整的逐步教程](https://gitbook.com/docs/guides/product-guides/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="/files/a3999ad66cd12e3e38c0dad06bb242b1761b578c" 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="/files/a8f44152c667906d62ee634781f1a0114fe6e4ed" alt=""><figcaption></figcaption></figure>
3. 点击 **经过身份验证的访问** 从侧边栏中的分类中。
4. 选择 **Auth0** 集成。
5. 点击 **在此站点上安装**.<br>

   <figure><img src="/files/dc69593c43e11fbf99c6c6440d40206e0bedc658" alt=""><figcaption></figcaption></figure>
6. 在你的站点上安装该集成后，你应该会看到该集成的配置界面：<br>

   <figure><img src="/files/83d373f58e436bd33c97ec80570ce0f5fb714bf2" alt=""><figcaption></figcaption></figure>
7. 输入 **域名**, **客户端 ID** 并 **客户端机密** 你在之前创建 Auth0 应用程序后复制的值。对于 Auth0 Domain，请输入从 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.
