CP Platform 개발자 가이드
CP 계정을 인증 서버로 사용하고, CP-Pay로 결제를 받고, CP-Notify로 알림을 보내는 방법.
5분 통합 (Quickstart)
1. 앱 등록
cp-platform.com/developers 콘솔에서 새 앱을 생성하면 다음 자격증명을 받습니다:
| 값 | 용도 | 노출 |
|---|---|---|
client_id | OAuth 요청 식별자 | 공개 (프론트엔드 OK) |
client_secret | OAuth 토큰 교환 | 비밀 (서버 전용) |
api_key | CP-Pay / CP-Notify 호출 | 비밀 (서버 전용) |
webhook_secret | webhook HMAC 검증 | 비밀 (서버 전용) |
앱 설정에서 redirect_uris 를 등록하세요. 로컬 개발용 http://localhost:3000/auth/callback 과 운영용 URL을 같이 넣어도 됩니다.
2. SDK install + 로그인 가드
npm i git+https://github.com/Copark-Dev/cp-auth-sdk.git#v0.5.2앱 루트에 Provider 한 번 mount:
import { CpAuthProvider } from "@cp-platform/auth-sdk/react";
<CpAuthProvider strict>
<App />
</CpAuthProvider>OAuth 클릭 핸들러 첫 줄에 가드 한 줄:
import { useCpAuth } from "@cp-platform/auth-sdk/react";
function LoginButton() {
const { guardOAuth } = useCpAuth();
return (
<button onClick={() => {
if (guardOAuth("google") !== "proceed") return; // 인앱 자동 처리
window.location.href = `https://auth.cp-platform.com/oauth/authorize?client_id=...`;
}}>Google 로그인</button>
);
}guardOAuth 가 Threads / Toss / KakaoBank / 쿠팡 / 배민 / 당근 / Discord 등 30+ 인앱 브라우저를 자동 감지해서 Android는 Chrome intent 로 escape, iOS 는 "Safari 에서 열기" 모달을 띄웁니다. 자세한 흐름은 자체 UI에 CP 인증 붙이기.
3. 백엔드에서 code → token 교환
여러분의 백엔드에서 SDK 헬퍼로 토큰 교환:
import { CpServerClient } from "@cp-platform/auth-sdk/server";
const cp = new CpServerClient(); // authUrl 기본값 https://auth.cp-platform.com
export async function POST(req: Request) {
const { code, codeVerifier } = await req.json();
const tokens = await cp.exchangeOAuthCode(code, codeVerifier);
const user = await cp.getUserInfo(tokens.access_token);
// user.sub 를 자기 DB profiles.cp_user_id 에 매핑 (federated identity)
return Response.json(tokens);
}JWT 검증은 verifyCpJwt로 (Supabase JWKS, ES256 자동):
import { verifyCpJwt } from "@cp-platform/auth-sdk/jwt";
const { cpUserId, email } = await verifyCpJwt(bearerToken);4. 결제 받기 (선택)
CP-Pay로 단건 결제 또는 구독을 받을 수 있습니다. CP-Pay 단건 결제 또는 구독 결제 를 참고하세요.
5. 알림 보내기 (선택)
이메일·SMS·카카오 알림톡·푸시를 단일 API로 보낼 수 있습니다. CP-Notify 를 참고하세요.
다음으로
- 로그인 UX를 결정해야 한다면 → 자기 도메인 vs CP 호스팅 비교
- 이미 등록은 끝났고 통합부터 빨리 → 자기 도메인 로그인 (권장)
- 전체 endpoint 카탈로그가 필요하다면 → API Reference