為 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 是另一條設定路徑。 |
Wanta