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

# 设置 OIDC

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

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

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

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

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

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

安装 OIDC 集成并添加所需配置。
{% 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="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-9c6eb6906e7538334ec7c87feb21d736ced5b599%2F25_04_10_setting_up_oidc_1.png?alt=media" 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 获得的回调 URL。

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

### 安装并配置 OIDC 集成

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

<figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-eacab294e24488e224d7378a7788c8958026486e%2F25_04_10_setting_up_oidc_2.png?alt=media" alt="A GitBook screenshot showing the OIDC integration installation"><figcaption></figcaption></figure>

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

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

它应该如下图所示：

<figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-6a1903abcc5ef080306f5fbc9579526a8b8e607c%2F25_04_10_setting_up_oidc_3.png?alt=media" alt="A GitBook screenshot showing the OIDC configuration screen"><figcaption></figcaption></figure>

对于 Client ID 和 Client Secret，粘贴你从身份提供商那里获得的值。

接下来，你需要找到身份提供商的授权端点和访问令牌端点。对于 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" %}
请查看你的身份提供商文档中允许的作用域列表，并输入限制最少的作用域值。我们只使用访问令牌来验证用户是否已通过身份验证，不会使用访问令牌获取任何进一步信息。因此，输入限制最少的作用域是最佳的安全建议。
{% endhint %}

点击 Save。

现在，在 GitBook 中关闭集成模态框，然后点击「管理站点」按钮。前往 **受众**，选择 **已验证身份的访问**，并选择 OIDC 作为后端。然后点击 **更新受众**。前往站点页面，然后点击 **发布**。\
\
现在，站点已发布，并由身份提供商控制已验证身份的访问。要进行试用，请点击「访问」。系统会要求你使用 OIDC 登录，以此确认站点已通过 OIDC 发布，并启用了已验证身份的访问。

### 启用 PKCE

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

### 配置注销

OIDC 集成可以结束已发布站点会话和身份提供商会话。

#### 设置结束会话端点

若要将访问者从上游身份提供商注销，请在以下位置输入其注销端点 **结束会话端点**.

访问者从已发布站点注销时，GitBook 会结束其已发布站点会话。GitBook 还会将其重定向到配置的端点，以结束其身份提供商会话。

#### 跳过注销确认提示

若要跳过上游身份提供商的注销确认页面，请启用 **跳过注销确认提示**.

访问者从已发布站点注销时，GitBook 会将其注销，而不显示该确认页面。


---

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