> 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/zhan-dian-fang-wen/authenticated-access/setting-up-oidc.md).

# 设置 OIDC

{% hint style="warning" %}
本指南将带你完成为你的文档设置受保护的登录界面。在继续本指南之前，请确保你已经先完成了以下流程： [启用经过身份验证的访问](/docs/documentation/zh/zhan-dian-fang-wen/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 中关闭 integrations 弹窗，然后点击 Manage site 按钮。导航到 **Audience**，选择 **Authenticated access**，并选择 OIDC 作为后端。然后，点击 **更新受众**。前往站点页面并点击 **发布**。\
\
该站点现在已在由你的 Auth0 应用控制的经过身份验证的访问之后发布。要试用它，请点击 Visit。系统会要求你使用 OIDC 登录，这证实了你的站点已通过 Auth0 在经过身份验证的访问之后发布。

### 启用 PKCE

如果你的身份提供方要求或建议使用 PKCE，请在 **Use 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/zhan-dian-fang-wen/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.
