瀏覽文件

Origo 帳號 OAuth 2.0 / OIDC 整合與開放資料格式

Origo 帳號中心 OAuth 2.0 / OpenID Connect 身分互聯規範(PKCE S256、JWKS、Scope 與不可變 sub 規則),以及 v5 備份封存檔 ZIP、閱讀淨化取代規則 JSON 與筆記匯出 Markdown 開放格式參考。

本頁目錄

本文件規範說明 Origo 帳號系統(https://account.origo.xin)的 OAuth 2.0 / OpenID Connect (OIDC) 串接協定,以及 Origo X 用戶端採用的開放、可移植本機資料格式(v5 備份封存檔、UTF-16 規範定位器、淨化取代規則 JSON 與閱讀筆記 Markdown 匯出)。公共平台介面請參閱開放生態工具包與公共 HTTP API 參考。

第一部分:Origo Account OAuth 2.0 / OIDC 整合指南

Origo 統一帳號中心作為 OIDC Identity Provider(簽發方 https://account.origo.xin),使用授權碼模式(Authorization Code)簽發短生命週期不透明 Bearer 存取權杖與 RS256 簽章的 JWT ID Token。

1. OIDC 自動探索與 JWKS 公鑰

  • Discovery 文件:GET https://account.origo.xin/.well-known/openid-configuration

核心中繼資料包括:

欄位 值
issuer https://account.origo.xin
authorization_endpoint https://account.origo.xin/api/v1/identity/authorize
token_endpoint https://account.origo.xin/api/v1/identity/token
userinfo_endpoint https://account.origo.xin/api/v1/identity/userinfo
third_party_entitlements_endpoint https://account.origo.xin/api/v1/identity/third-party/entitlements
jwks_uri https://account.origo.xin/api/v1/identity/jwks
response_types_supported ["code"]
grant_types_supported ["authorization_code"]
subject_types_supported ["public", "pairwise"]
id_token_signing_alg_values_supported ["RS256"]
token_endpoint_auth_methods_supported ["client_secret_post", "client_secret_basic"]
scopes_supported ["openid", "email", "profile", "entitlements"]
code_challenge_methods_supported ["S256"]
  • JWKS 公鑰端點:GET https://account.origo.xin/api/v1/identity/jwks 回傳用於驗證 id_token RS256 簽章的公鑰集合(含 alg: "RS256"、use: "sig" 與 kid)。

2. 發起授權請求(強制 PKCE S256 與 nonce)

將使用者瀏覽器重新導向至:

GET https://account.origo.xin/api/v1/identity/authorize
參數 必填 約束與說明
response_type 是 固定為 code
client_id 是 已註冊的應用用戶端 ID
redirect_uri 是 必須與預先精確註冊的回呼位址完全一致
scope 是 空白分隔的權限範圍,須包含 openid
state 是 防 CSRF 隨機字串,長度 16–512 字元
nonce 是(第三方必傳) 防重播隨機字串,長度 16–256 字元,寫入簽發的 id_token
code_challenge 是(第三方必傳) BASE64URL(SHA256(code_verifier))
code_challenge_method 是 固定為 S256(不支援 plain)
prompt 否 可選 none(靜默授權)、login、create、add_account
screen_hint 否 可選 reset(直達重設密碼檢視)
login_hint 否 可選帳號 UUID,用於在同瀏覽器多帳號工作階段中指定目標帳號

授權請求 URL 查詢字串上限為 8 KiB,依 IP 限流為每 15 分鐘 30 次(全域每 15 分鐘 1200 次)。

3. 權杖兌換(Token Endpoint)

收到回呼中的 code 與校驗一致的 state 後,伺服端在後端通道呼叫:

POST https://account.origo.xin/api/v1/identity/token
Content-Type: application/x-www-form-urlencoded
  • 單次 60 秒授權碼:code 僅可使用 1 次,有效期 60 秒,且嚴格繫結簽發時的 client_id 與 redirect_uri。
  • 用戶端驗證方式:支援 client_secret_basic(HTTP Authorization: Basic ...)或 client_secret_post(表單提交 client_id 與 client_secret)。嚴禁在同一次請求中混用兩種驗證方式。
  • PKCE 校驗:提交 code_verifier(長度 43–128 字元),伺服端驗證其 S256 摘要與授權階段一致。
  • 回應載荷:請求表單上限 8 KiB,成功回傳 JSON:
{
  "access_token": "<opaque-bearer-token>",
  "token_type": "Bearer",
  "expires_in": 300,
  "id_token": "<rs256-jwt>",
  "scope": "openid profile email"
}
  • ID Token 驗章清單:呼叫方必須使用 JWKS 公鑰校驗 RS256 簽章,核驗 iss == "https://account.origo.xin"、aud == client_id、nonce 符合發起工作階段以及 iat / exp(有效期 5 分鐘)未過期。

4. UserInfo、Scope 權限與不可變 sub 規則

使用 Authorization: Bearer <access_token> 請求 GET https://account.origo.xin/api/v1/identity/userinfo:

  • openid:回傳永久不變的帳戶主體識別 sub。
    • 不可變 sub 原則:第一方應用(public)的 sub 為帳戶原始 UUID;第三方開放應用(pairwise)的 sub 為依用戶端隔離的穩定不透明識別(以 opw_ 開頭)。嚴禁使用 email 或 preferred_username 作為使用者主鍵或執行跨帳號電子郵件自動合併,唯一主鍵必須繫結 (issuer, sub)。
  • profile:回傳 preferred_username(若使用者未設定使用者名稱,可能提供 origo_<14位十六進位> 作為展示/建帳提示,不可作身分鍵)、name(顯示名稱)以及頭像 picture(如已設定)。
  • email:回傳 email 與布林值 email_verified。
  • entitlements:回傳唯讀會員與服務權益摘要。第三方應用還可在使用者授權有效期內,憑用戶端憑證與 sub 呼叫 POST https://account.origo.xin/api/v1/identity/third-party/entitlements 重新整理最新權益狀態;若使用者已撤銷授權,介面將回傳 403(grant_revoked)。已停用或已註銷帳號無法完成授權、兌換權杖或讀取 UserInfo。

5. WebAuthn 跨來源 Passkey(Related Origin Requests)

Origo 網站在 https://origox.site/.well-known/webauthn 公開宣告了關聯來源白名單:

{
  "origins": ["https://account.origo.xin"]
}

在支援 WebAuthn Related Origin Requests 的現代瀏覽器(Chromium 129+、Safari 18+、Firefox 152+)中,使用者在 origox.site 繫結的 Passkey(RP ID 為 origox.site)可在統一登入頁 account.origo.xin 直接驗證,無需重新註冊憑證。

第二部分:開放可移植資料格式

Origo X 堅持本機優先與資料可攜原則,所有使用者備份、定位、淨化規則與筆記匯出均採用公開可讀的結構化格式。

1. v5 備份封存檔格式(.zip + .complete)

本機與 WebDAV 備份皆輸出統一命名格式:origo-x-<UTC 毫秒時間戳記>-<UUID>.zip,並在上傳完成後寫入同名前綴的 .complete 校驗標記檔案(內容為整個 ZIP 檔案的 64 位元小寫 SHA-256)。

封存檔目錄結構

origo-x-1795852800000-<uuid>.zip
├── manifest.json       # 封存清單、格式版本與全部檔案 SHA-256 校驗對映
├── records.jsonl       # UTF-8 JSON Lines,每行一條 PortableRecord v2
├── assets/<sha256>     # 依內容摘要定址的書籍正文、封面與 sidecar(STORE 無壓縮儲存)
└── credentials.jsonl   # 可選;僅在本機明確勾選匯出憑證時存在(WebDAV 永不匯出)

manifest.json 核心結構

{
  "format": "origo-x-backup",
  "version": 5,
  "createdAt": "2026-11-28T08:00:00.000Z",
  "platform": "macos",
  "scope": {
    "reading": true,
    "statistics": true,
    "sources": true,
    "settings": true
  },
  "recordCount": 128,
  "files": {
    "records.jsonl": "<64-hex-sha256>",
    "assets/<sha256>": "<64-hex-sha256>",
    "manifest.json": "<64-hex-sha256>"
  }
}

records.jsonl 與 PortableRecord v2 記錄模型

每行是一個精確包含 7 個鍵的 JSON 物件,所有業務欄位統一使用 camelCase,不暴露任何本機 SQLite 自動遞增列 ID 或平台絕對路徑:

{
  "key": "note:9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
  "kind": "note",
  "uid": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
  "rev": 0,
  "modifiedMs": 1795852800000,
  "device": "backup",
  "value": {
    "bookUid": "book-uuid",
    "content": "摘錄文字",
    "type": "highlight",
    "readerNote": "批註內容",
    "canonicalLocator": "{...}",
    "createdMs": 1795852000000,
    "updatedMs": 1795852800000
  }
}

支援的核心 kind 型別包括:book、asset(uid 為 sha256(bookUid + "\0" + role),role 取 file / cover / sidecar)、binding、position、bookmark、note、session、folder、membership、sourceDefinition、source、sourceGroup、preference、legacyDaily、bookVersionRecord(另有僅用於官方同步的 bookMerge 與僅用於本機加密備份的 credential)。

規範 UTF-16 定位器(CanonicalLocator v1)

閱讀進度、書籤與筆記攜帶版面無關的 CanonicalLocator JSON 字串,確保跨字級、跨螢幕穩定還原:

  • 核心欄位:version(1)、format(epub / txt / pdf 等)、href(text://chapter/{id}/offset/{n}/excerpt/{text})、chapterId、resourceHref、progression(0.0–1.0)、positionHint、totalPositionsHint、fragments、contentSignature。
  • textAnchor 物件:quote、prefix、suffix、chapterId、resourceHref、startOffsetUtf16(UTF-16 碼元位移)、lengthUtf16、offsetHint。

體積上限與安全校驗邊界

  • 單一解壓檔案上限 2 GiB,封存檔解壓總計上限 8 GiB,manifest.json 與 records.jsonl 各自上限 64 MiB,最多 20,000 個封存項目。
  • 校驗階段在修改任何使用者資料前執行:先讀取 ZIP 中央目錄拒絕加密項目、Unix 符號連結、路徑越界(..)與大小寫碰撞;隨後依串流解壓逐塊校驗真實輸出位元組數與 manifest.json 宣告的 SHA-256 精確一致,拒絕一切偽造大小、截斷或未帶有效 .complete 標記的封存檔。

2. 閱讀淨化取代規則 JSON Schema(ReplaceRule)

淨化規則支援批次匯入/匯出為 UTF-8 JSON 陣列檔案(單一檔案匯入上限 8 MiB,規則庫上限 5,000 條,單條模式上限 20,000 字元):

欄位 型別 說明(含舊版相容別名)
id integer / string 規則唯一識別
name string 規則名稱(相容舊欄位 replaceSummary)
pattern string 比對模式或正規表示式(必填,相容舊欄位 regex)
replacement string 取代文字(支援擷取群組 $1)
group string 規則分組名稱
scope string 生效書名/書源範圍(相容舊欄位 useTo)
excludeScope string 排除範圍
isEnabled boolean 是否啟用(相容 enabled / enable)
isRegex boolean 是否依正規表示式執行
scopeTitle boolean 是否作用於章節標題
scopeContent boolean 是否作用於正文內容
scopeSource boolean 是否比對書源
previewText string? 可選測試預覽範例
order integer 執行排序權重(相容 sortOrder / serialNumber)
timeoutMillisecond integer 單條正規表示式逾時毫秒數,預設 3000(相容 timeout)
[
  {
    "id": 101,
    "name": "清理章節末尾廣告",
    "pattern": "\\n*(本章完.*?)",
    "replacement": "",
    "group": "通用淨化",
    "scope": "",
    "excludeScope": "",
    "isEnabled": true,
    "isRegex": true,
    "scopeTitle": false,
    "scopeSource": false,
    "scopeContent": true,
    "order": 1,
    "timeoutMillisecond": 3000
  }
]

匯入校驗會拒絕空 pattern、語法非法的正規表示式以及 scopeTitle 與 scopeContent 同時為 false 的無效規則。

3. 閱讀筆記 Markdown 匯出與偏好可移植格式

  • 閱讀筆記 Markdown 匯出(ReadingDataMarkdownRenderer):以 YAML Frontmatter 開頭(含 title、author、exported_at UTC ISO 8601 時間戳記、annotation_count),正文中保留書籍標題、彙總統計區塊引用,並依章節 ## 章節名 與型別 ### 畫線 / 底線 / 筆記 分組輸出摘錄引用、使用者批註與頁碼標記:
---
title: "範例書籍"
author: "範例作者"
exported_at: "2026-11-28T08:00:00.000Z"
annotation_count: 1
---

# 《範例書籍》

> **作者**:範例作者  
> **整本書** · 1 畫線 · 0 底線 · 0 筆記  
> **匯出時間**:2026-11-28T16:00:00.000

---

## 第一章

### 畫線

> 摘錄的原文段落內容。

**我的筆記**

個人批註內容。

`第 12 頁`
  • 閱讀偏好可移植格式:應用程式設定依據 PreferencesRegistry 嚴格區分可移植外觀/閱讀偏好與裝置局部路徑、安全金鑰或可重建快取。可移植偏好透過 Backup Archive v5 中 kind: "preference" 的 PortableRecord(uid 與 key 為偏好鍵名,value 為 JSON 值)以及隨附外觀資源清單(自訂字型、閱讀背景、自訂 SVG 與主題包)在跨裝置間無損移轉。

相關閱讀:開放生態工具包與公共 HTTP API 參考、帳號與登入、備份與還原、筆記與畫線、淨化與取代規則。

發現文件中的問題? 提出修正