---
author: OOMOL
author_url: https://oomol.com/zh-cn/about/
title: 为 OpenConnector 创建 Notion OAuth app
description: 创建 Notion public connection，配置 OAuth redirect URI，并把 Notion 连接到
  OOMOL OpenConnector。
lang: zh-CN
canonical_url: https://oomol.com/zh-cn/docs/openconnector-notion-oauth-app/
markdown_url: https://oomol.com/zh-cn/docs/openconnector-notion-oauth-app.md
---

# 为 OpenConnector 创建 Notion OAuth app

当 OpenConnector 需要通过 OAuth 让用户授权 workspace pages 或 databases 时，使用 Notion public connection。Notion 也支持 internal integration secret；如果你需要用户授权流程，请使用 OAuth。

## OpenConnector service

| Service ID | Provider | Auth type |
| --- | --- | --- |
| `notion` | Notion | OAuth2 |

OpenConnector 的 Notion OAuth provider 请求 `read_content`、`insert_content` 和 `update_content` 等 capabilities。

## 前置条件

- 一个正在运行的 OpenConnector runtime。
- 可以访问 Notion integrations developer portal。
- 有权限创建 public connection。
- 用户在浏览器中打开的 OpenConnector origin，例如 `http://localhost:3000` 或 `https://connect.example.com`。

## 第 1 步：确定 OpenConnector callback URL

在 OpenConnector origin 后拼接 `/oauth/callback`，得到 callback URL。本地测试使用 `http://localhost:3000/oauth/callback`。公开部署时，请先设置 `OOMOL_CONNECT_ORIGIN`，重启 OpenConnector 后使用公开 callback URL，例如 `https://connect.example.com/oauth/callback`。

## 第 2 步：创建 Notion public connection

在 [Notion integrations developer portal](https://www.notion.com/my-integrations) 中：

1. 创建新的 public connection。
2. 填写 connection name 和 workspace 信息。
3. 在 OAuth redirect URI 配置中添加 OpenConnector 的准确 callback URL。
4. 选择适合你的 installation scope。
5. 配置 OpenConnector actions 需要的 content capabilities。
6. 保存 connection。

Notion 官方文档见 [Authorization](https://developers.notion.com/guides/get-started/authorization)。Notion 说明 public connection 创建时会选择 installation scope，请谨慎选择。

## 第 3 步：复制 client credentials

从 Notion public connection 设置中复制：

| Notion 字段 | OpenConnector 字段 |
| --- | --- |
| OAuth client ID | `clientId` |
| OAuth client secret | `clientSecret` |

## 第 4 步：在 OpenConnector 中保存 Notion client

优先使用 OpenConnector Web 控制台：

1. 打开 OpenConnector Web 控制台，例如 `http://localhost:3000`。
2. 打开 **Providers**，选择 **Notion**。
3. 点击 **Configure OAuth Client** 或 **Edit OAuth Client**。
4. 粘贴 Notion client ID 和 client secret。
5. 点击 **Save OAuth Client**。

## 第 5 步：连接并测试

保存 OAuth client 后，在 Notion provider 页面点击 **Connect**。选择要分享的 Notion workspace content，批准访问，回到 OpenConnector，并确认 provider 页面显示 workspace 已连接。

连接后可在控制台 action 列表中运行 `notion.search` 或 `notion.list_users` 做低风险测试。

## 排查建议

| 现象 | 检查项 |
| --- | --- |
| Notion 拒绝 redirect URI | Notion 中的 OAuth redirect URI 必须和 `<openconnector-origin>/oauth/callback` 完全一致。 |
| 找不到已分享内容 | 授权时选择 connection 可以访问的 pages 或 databases。Notion access 会受 shared content 限制。 |
| 写入 action 失败 | 确认 Notion connection 有 insert 或 update content capabilities，并且分享的 page/database 允许该操作。 |
| 连接了错误 workspace | 使用已登录目标 Notion workspace 的浏览器 profile 启动授权。 |
| 混淆 internal integration token 和 OAuth | 本文使用 OAuth client ID 和 client secret。Internal integration secret 是另一条配置路径。 |
