> 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-oidc.md).

# 设置 OIDC

{% hint style="warning" %}
本指南将带你完成为你的文档设置受保护登录页的过程。在继续本指南之前，请确保你已经先完成了以下过程： [启用身份验证访问](/docs/documentation/zh/fa-bu/site-audience/authenticated-access/enabling-authenticated-access.md).
{% endhint %}

要使用 OIDC 为你的 GitBook 站点设置受身份验证保护的访问，流程如下：

{% stepper %}
{% step %}
**在你的身份提供商中创建一个新应用**

从你的身份提供商控制台创建一个应用。
{% endstep %}

{% step %}
**安装并配置 OIDC 集成**

安装 Auth0 集成并添加所需配置。
{% endstep %}
{% endstepper %}

OIDC 代表 OpenID Connect，它是构建在 OAuth 之上的身份层。许多身份提供商都遵循 OIDC，而 GitBook 的 OIDC 受身份验证访问集成允许你将内容发布在受身份验证保护之下，而内容的访问由你的身份提供商控制

{% hint style="info" %}
由于本指南是面向所有身份提供商的通用指南，某些细节可能会因你的身份提供商而异。为便于说明，本指南使用 Google 作为身份提供商。
{% endhint %}

### 在你的身份提供商中创建一个新应用

要让集成正常工作，你需要在身份提供商中进行一些设置。

你需要在身份提供商中创建一个新应用。其类型应为“Web Application”。在 Google 中，你可以在“API and Services”、“Credentials”，然后在“OAuth 2.0 Client IDs”下创建。\\

<figure><img src="/files/52a98326e501f1f2b9f8e1cc472f6bb6cfb03953" alt="A screenshot showing creation of an OAuth client in an identity provider"><figcaption></figcaption></figure>

点击 Create Credentials，选择 OAuth Client ID，将类型设为 Web Application，适当命名，并在 Authorized Redirect URIs 下输入你从 GitBook 获得的 Callback URL。

点击 Create。记下 Client ID 和 Client Secret。我们需要它们来完成在 GitBook 中对集成的配置。

### 安装并配置 OIDC 集成

在 GitBook 应用中进入 integrations，选择 authenticated access 作为类别，然后安装 OIDC 集成。将 OIDC 集成安装到你选择的文档站点上。

<figure><img src="/files/bade552ed17050e3e2e108973b89e4b26d0814d1" alt="A GitBook screenshot showing the OIDC integration installation"><figcaption></figcaption></figure>

在你的网站上安装后，进入 configuration，并记下位于 Save 按钮上方的 Callback URL。我们可能需要它来设置身份提供商。

打开你安装了该集成的部分的 OIDC 集成配置界面。

它应该如下图所示

<figure><img src="/files/8ac1c1efe47e166a789e7631b03226a63078bd5d" alt="A GitBook screenshot showing the OIDC configuration screen"><figcaption></figcaption></figure>

在 Client ID 和 Client Secret 中，粘贴你从身份提供商获取的值。

现在，你需要找到你的身份提供商的 Authorization Endpoint 和 Access Token Endpoint。对于 Google，它们分别是 `https://accounts.google.com/o/oauth2/v2/auth` 并 `https://oauth2.googleapis.com/token` 分别是。

{% hint style="info" %}
如果你不使用 Google，这些端点会有所不同。请查阅你的身份提供商文档以找到这些端点
{% endhint %}

对于 OAuth Scope，其值同样会因你的身份提供商而异。以 Google 为例，你可以输入 `openid`.

{% hint style="info" %}
请查看你的身份提供商文档中允许的 scope 列表，并输入限制最少的 scope 值。我们仅使用 Access Token 来验证用户是否已通过身份验证，不会使用 Access Token 获取任何其他信息。因此，输入限制最少的 scope 是最佳安全建议。
{% endhint %}

点击保存。

现在，在 GitBook 中关闭集成模态窗口，然后点击 Manage site 按钮。导航到 **受众**，选择 **经过身份验证的访问**，并选择 OIDC 作为后端。然后，点击 **更新受众**。进入站点页面并点击 **发布**.\
\
该站点现已发布在由你的 Auth0 应用控制的受身份验证保护之后。要试用它，请点击 Visit。系统会要求你使用 OIDC 登录，这确认了你的网站已通过 Auth0 发布在受身份验证保护之后。

### 启用 PKCE

如果你的身份提供商要求或建议使用 PKCE，请打开 **使用 PKCE** 在 OIDC 集成配置界面中启用该选项。此选项会为该集成与身份验证提供商发起的授权码流程启用 Proof Key for Code Exchange（PKCE）。


---

# 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-oidc.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.
