---
title: 為 OpenConnector 建立 Notion OAuth app
description: 建立 Notion public connection，設定 OAuth redirect URI，並將 Notion 連線到
  OOMOL OpenConnector。
lang: zh-TW
canonical_url: https://oomol.com/zh-tw/docs/openconnector-notion-oauth-app/
markdown_url: https://oomol.com/zh-tw/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 是另一條設定路徑。 |
