PKCE로 고객 승인
ShareAI 인증 코드 흐름을 S256 PKCE로 구현하고, 상태를 확인한 후 애플리케이션 백엔드에서 코드를 교환하세요.
이 페이지에서
이 흐름은 하나의 고객 계정을 애플리케이션에 연결합니다. 고객은 로그인하고 개인 또는 조직 계정을 선택한 후 요청된 권한을 승인합니다. 그런 다음 백엔드에서 단기 코드와 토큰을 교환합니다.
시작하기 전에#
완료 애플리케이션 등록. 정확히 등록된 콜백, 서버에 저장된 클라이언트 자격 증명 및 브라우저에서 인증을 완료하는 서버 측 세션이 필요합니다.
1. 인증 요청 생성#
https://auth.shareai.now/oauth/authorize고객에게 애플리케이션 인증을 요청하세요.
- 기본 URL
https://auth.shareai.now- 인증
- 브라우저 리디렉션; 등록된 애플리케이션
각 시도마다 새로운 검증자, 상태 및 논스를 생성하세요. 이를 시작하는 사용자의 서버 측 세션에 저장하세요. 브라우저 리디렉션에서 SHA-256 챌린지를 보내고, 검증자는 절대 보내지 마세요. 애플리케이션이 필요한 범위만 요청하세요.
Python
import base64
import hashlib
import secrets
import urllib.parse
verifier = secrets.token_urlsafe(48)
challenge = base64.urlsafe_b64encode(hashlib.sha256(verifier.encode()).digest()).rstrip(b"=").decode()
state = secrets.token_urlsafe(32)
nonce = secrets.token_urlsafe(32)
# Store verifier, state and nonce in the user's server-side session.
params = {
"response_type": "code",
"client_id": "YOUR_CLIENT_ID",
"redirect_uri": "https://app.example.com/auth/shareai/callback",
"scope": "openid profile surcharge",
"state": state,
"nonce": nonce,
"code_challenge": challenge,
"code_challenge_method": "S256",
}
print("https://auth.shareai.now/oauth/authorize?" + urllib.parse.urlencode(params))
TypeScript
import { randomBytes, createHash } from "node:crypto";
const verifier = randomBytes(48).toString("base64url");
const state = randomBytes(32).toString("base64url");
const nonce = randomBytes(32).toString("base64url");
const challenge = createHash("sha256").update(verifier).digest("base64url");
// Save verifier, state and nonce in the initiating server-side session.
const params = new URLSearchParams({ response_type: "code", client_id: "YOUR_CLIENT_ID",
redirect_uri: "https://app.example.com/auth/shareai/callback",
scope: "openid profile surcharge", state, nonce,
code_challenge: challenge, code_challenge_method: "S256" });
const authorizationUrl = `https://auth.shareai.now/oauth/authorize?${params}`;
// Redirect the browser to authorizationUrl.
2. 콜백 검증#
인증이 거부된 경우, OAuth 오류를 일반적인 취소로 처리하세요. 그렇지 않으면 반환된 state 값을 저장된 값과 비교한 후 코드를 사용하세요. 누락되거나 일치하지 않는 상태를 거부하세요. 저장된 상태는 한 번만 사용하고, 다른 브라우저 세션에서 제출된 콜백 URL은 허용하지 마세요.
3. 코드 교환#
https://auth.shareai.now/oauth/token일회용 코드와 일치하는 PKCE 검증자를 교환하세요.
- 기본 URL
https://auth.shareai.now- 인증
- 기밀 클라이언트 인증
cURL
curl --fail-with-body "https://auth.shareai.now/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "client_id=$SHAREAI_CLIENT_ID" \
--data-urlencode "client_secret=$SHAREAI_CLIENT_SECRET" \
--data-urlencode "code=$AUTHORIZATION_CODE" \
--data-urlencode "redirect_uri=https://app.example.com/auth/shareai/callback" \
--data-urlencode "code_verifier=$PKCE_VERIFIER"
클라이언트에 구성된 인증 방법을 사용하세요. 예제는 양식 기반 클라이언트 인증을 사용합니다. 동일한 코드를 두 번 보내지 마세요; 소비되거나 만료된 코드 이후에는 인증을 다시 시작하세요.
4. 결과 저장 및 앱 세션 설정#
액세스 및 갱신 토큰을 백엔드에 저장하세요. 반환된 expires_in 값을 사용하고 영구 토큰으로 가정하지 마세요. ID 토큰을 사용하는 경우, 발급자의 JWKS, 예상 발급자, 클라이언트 대상, 만료 및 원래 논스를 사용하여 서명을 검증한 후 클레임을 신뢰하세요.
라이프사이클 계속하기#
마지막 업데이트 9월 15, 2026