瀏覽文件

為 OpenConnector 建立 Notion OAuth app

當 OpenConnector 需要透過 OAuth 讓使用者授權 workspace pages 或 databases 時,請使用 Notion public connection。Notion 也支援 internal integration secret;如果你需要使用者授權流程,請使用 OAuth。

OpenConnector service

Service IDProviderAuth type
notionNotionOAuth2

OpenConnector 的 Notion OAuth provider 會請求 read_contentinsert_contentupdate_content 等 capabilities。

前置條件

  • 一個正在運作的 OpenConnector runtime。
  • 可以存取 Notion integrations developer portal。
  • 有權限建立 public connection。
  • 使用者在瀏覽器中開啟的 OpenConnector origin,例如 http://localhost:3000https://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 中:

  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。Notion 說明 public connection 建立時會選擇 installation scope,請謹慎選擇。

第 3 步:複製 client credentials

從 Notion public connection 設定中複製:

Notion 欄位OpenConnector 欄位
OAuth client IDclientId
OAuth client secretclientSecret

第 4 步:在 OpenConnector 中儲存 Notion client

優先使用 OpenConnector Web 主控台:

  1. 開啟 OpenConnector Web 主控台,例如 http://localhost:3000
  2. 開啟 Providers,選擇 Notion
  3. 點擊 Configure OAuth ClientEdit 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.searchnotion.list_users 做低風險測試。

疑難排解建議

現象檢查項目
Notion 拒絕 redirect URINotion 中的 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 是另一條設定路徑。