为 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 中:
- 创建新的 public connection。
- 填写 connection name 和 workspace 信息。
- 在 OAuth redirect URI 配置中添加 OpenConnector 的准确 callback URL。
- 选择适合你的 installation scope。
- 配置 OpenConnector actions 需要的 content capabilities。
- 保存 connection。
Notion 官方文档见 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 控制台:
- 打开 OpenConnector Web 控制台,例如
http://localhost:3000。 - 打开 Providers,选择 Notion。
- 点击 Configure OAuth Client 或 Edit OAuth Client。
- 粘贴 Notion client ID 和 client secret。
- 点击 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 是另一条配置路径。 |