跳至主要內容

AI agents can use the SimplePost documentation index at /llms.txt to find related guides.

Bluesky OAuth 應用程式設定

Bluesky 使用 AT Protocol OAuth。目前沒有集中式的開發者應用程式註冊入口網站,您的應用程式是透過一份公開的用戶端中繼資料 JSON 文件來識別。

託管版 Scheduler 會提供其 Bluesky OAuth 用戶端。本機 CLI 的 OAuth 連線則使用您自行託管的用戶端中繼資料 URL,設定於 SIMPLE_POST_BLUESKY_CLIENT_ID。若想以較簡單的方式設定本機 SDK,可使用應用程式密碼;或將 CLI 連接到託管版 Scheduler,以重複使用既有帳號。

用戶端中繼資料​

請將 JSON 文件託管在公開的 HTTPS URL。該文件的 URL 同時也是 client_id。

瀏覽器或公開用戶端範例:

{
"client_id": "https://yourapp.com/oauth/client-metadata.json",
"application_type": "web",
"client_name": "Your App Name",
"client_uri": "https://yourapp.com",
"dpop_bound_access_tokens": true,
"grant_types": ["authorization_code", "refresh_token"],
"redirect_uris": ["https://yourapp.com/oauth/callback"],
"response_types": ["code"],
"scope": "atproto transition:generic",
"token_endpoint_auth_method": "none"
}

機密伺服器端用戶端範例:

{
"client_id": "https://yourapp.com/oauth/client-metadata.json",
"application_type": "web",
"client_name": "Your App Name",
"client_uri": "https://yourapp.com",
"dpop_bound_access_tokens": true,
"grant_types": ["authorization_code", "refresh_token"],
"redirect_uris": ["https://yourapp.com/oauth/callback"],
"response_types": ["code"],
"scope": "atproto transition:generic",
"token_endpoint_auth_method": "private_key_jwt",
"token_endpoint_auth_signing_alg": "ES256",
"jwks": {
"keys": [
{
"kty": "EC",
"crv": "P-256",
"x": "YOUR_PUBLIC_KEY_X",
"y": "YOUR_PUBLIC_KEY_Y",
"kid": "key-1"
}
]
}
}

必填欄位​

欄位是否必填說明
client_id是必須與中繼資料 URL 完全相符。
dpop_bound_access_tokens是必須為 true。
grant_types是使用 authorization_code 與 refresh_token。
redirect_uris是回呼 URL 清單。
response_types是使用 code。
scope是必須包含 atproto。
token_endpoint_auth_method否公開用戶端使用 none,機密用戶端使用 private_key_jwt。

產生 ES256 金鑰​

使用 Node.js:

import crypto from "node:crypto";

const { privateKey, publicKey } = crypto.generateKeyPairSync("ec", {
namedCurve: "P-256",
});

const privateJwk = privateKey.export({ format: "jwk" });
const publicJwk = publicKey.export({ format: "jwk" });

privateJwk.kid = "key-1";
publicJwk.kid = "key-1";

console.log("Public JWK:", JSON.stringify(publicJwk, null, 2));
console.log("Private JWK:", JSON.stringify(privateJwk, null, 2));

請將私密金鑰保存在密鑰管理工具或加密的伺服器設定中。公開金鑰則放入中繼資料文件。

OAuth 流程要求​

Bluesky OAuth 使用:

  • 以 PKCE 進行授權碼交換。
  • PAR,即推送式授權請求(pushed authorization requests)。
  • 用於權杖與 API 請求的 DPoP 證明。
  • 處理來自 DPoP-Nonce 標頭的 nonce。

Scheduler 已為已連接的 Bluesky 帳號實作上述機制。若您要自行建置 OAuth 流程,請盡可能使用官方的 AT Protocol OAuth 函式庫。