인증
본인 계정에는 API 키를 사용하세요. 다른 사람의 계정으로 게시하려면 OAuth 앱을 등록하세요.
API 키
키를 Bearer 토큰으로 보냅니다: Authorization: Bearer pst_live_.... 라이브 키는 실제 계정에 작동하고, 테스트 키(pst_test_...)는 샌드박스입니다.
키에는 scope가 있으며, scope 밖의 요청은 403이 됩니다. 키는 IP 주소로 제한하거나 만료일을 지정할 수도 있습니다. 키를 교체하면 이전 키는 잠시 동안 계속 작동합니다.
Scope
| Scope | 허용 범위 |
|---|---|
channels:read | 연결된 채널 목록 조회 |
posts:read | 게시물 조회 및 post.* webhook 이벤트 수신 |
posts:write | 게시물 생성, 수정, 삭제, 예약, 발행 |
media:write | 게시물에 미디어 첨부 |
analytics:read | 게시 및 오디언스 분석 조회 |
webhooks:manage | webhook 엔드포인트 관리 |
앱용 OAuth
콘솔에서 앱을 등록하세요. 사용자가 요청한 scope를 승인하면 해당 사용자 계정용 토큰을 받게 됩니다. 메타데이터는 https://pub.postia.app/.well-known/oauth-authorization-server에 있습니다.
- 사용자를
https://pub.postia.app/oauth/authorize로 보내며,response_type=code,client_id,redirect_uri,scope(공백으로 구분),state, 그리고code_challenge_method=S256과 함께 PKCEcode_challenge를 전달합니다. POST /oauth/token에서grant_type=authorization_code,code,redirect_uri,code_verifier로 코드를 교환합니다. 비공개 앱은 클라이언트 시크릿도 함께 보냅니다.- 액세스 토큰(
pst_at_...)을 Bearer 토큰으로 사용해 API를 호출합니다. 유효 시간은 1시간입니다. grant_type=refresh_token으로 갱신합니다. 리프레시 토큰(pst_rt_...)은 사용할 때마다 새것으로 교체됩니다. 폐기는POST /oauth/revoke에서 합니다.
import { createHash, randomBytes } from "node:crypto";
const verifier = randomBytes(32).toString("base64url");
const challenge = createHash("sha256").update(verifier).digest("base64url");
const url = new URL("https://pub.postia.app/oauth/authorize");
url.search = new URLSearchParams({
response_type: "code",
client_id: CLIENT_ID,
redirect_uri: REDIRECT_URI,
scope: "channels:read posts:write",
state: randomBytes(16).toString("hex"),
code_challenge: challenge,
code_challenge_method: "S256",
});
// Send the user to url, keep verifier with their session.
curl -X POST https://pub.postia.app/oauth/token \
-d grant_type=authorization_code \
-d code=CODE_FROM_THE_REDIRECT \
-d redirect_uri=REDIRECT_URI \
-d client_id=CLIENT_ID \
-d code_verifier=VERIFIER
리디렉션 URI는 정확히 일치해야 하며, https 또는 localhost의 http만 허용됩니다. 공개 앱은 다른 사람이 연결하기 전에 검토를 거치며, 그때까지는 소유자만 연결할 수 있습니다.