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

# 已认证访问

为你已发布的内容设置自定义身份验证

身份验证访问可让您发布内容，同时要求任何想要查看内容的访客进行身份验证。启用后，GitBook 会让您的身份验证提供方来处理谁可以访问内容。

<figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-63ef53d9554190f9c6d459545cb3cd11acc8b31e%2F26_01_06_authenticated_access%402x.png?alt=media" alt="A screenshot showing a login screen for docs behind authenticated access"><figcaption><p>为你已发布的文档添加登录入口。</p></figcaption></figure>

### 使用场景

身份验证访问的常见使用场景包括：

* 发布应仅供付费客户、潜在客户或合作伙伴访问的敏感产品文档。
* 发布内部知识库内容，这些内容只能供公司员工访问。

### 工作原理

设置身份验证访问时，您可以选择两种方法：

1. 安装我们支持的身份验证集成之一——我们支持 Okta、Azure 和 Auth0。我们 **强烈推荐** 如果您使用的是我们支持的身份验证提供商，建议选择此选项。
2. 创建并托管您自己的服务器来处理身份验证。可以使用许多不同的技术，但由您来编写代码并维护您选择的解决方案。

### 内置登录和登出 URL

GitBook 为您在已发布的网站上提供内置的登录和登出 URL：

* `<publishedSiteURL>/~gitbook/auth/login`
* `<publishedSiteURL>/~gitbook/auth/logout`

可在任何需要登录链接的地方使用登录 URL，例如您网站中的页眉链接。

当访客打开登录 URL 时，GitBook 会将其重定向到为该站点配置的身份验证后端。这适用于集成后端和自定义后端。

GitBook 还会添加一个 `location` 查询参数，其值与访客最初访问的页面相对应。你的后端可以使用该值，在访客登录后将其送回同一页面。

使用登出 URL 可使访客退出其 GitBook 会话。

前往 [启用经过身份验证的访问](https://gitbook.com/docs/documentation/zh/publish/site-audience/authenticated-access/enabling-authenticated-access.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 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.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.
