devhub
devhub2mo ago

토스 본인확인 API 연동 관련 문의

TOSS_API_KEY = "test_sk_L"
TOSS_AUTH_REQUEST_URL = "https://cert.toss.im/api/v2/sign/user/auth/id/request"

@app.route("/auth/verify-identity", methods=["POST"])
def verify_identity():
user_id = session.get("user_id")
if not user_id:
return jsonify({"success": False, "message": "로그인 필요"})

tx_id = secrets.token_hex(16) # 랜덤 트랜잭션 ID

payload = {
"requestType": "USER_NONE",
}
headers = {
"Authorization": f"Bearer {TOSS_API_KEY}",
"Content-Type": "application/json"
}

try:
response = requests.post(TOSS_AUTH_REQUEST_URL, headers=headers, json=payload)
result = response.json()
except Exception as e:
return jsonify({"success": False, "message": f"API 요청 실패: {e}"})

if result.get("success"):
return jsonify({
"success": True,
"authUrl": result.get("authUrl"),
"txId": result.get("txId")
})
else:
return jsonify({"success": False, "message": "토스 본인인증 실패"})
TOSS_API_KEY = "test_sk_L"
TOSS_AUTH_REQUEST_URL = "https://cert.toss.im/api/v2/sign/user/auth/id/request"

@app.route("/auth/verify-identity", methods=["POST"])
def verify_identity():
user_id = session.get("user_id")
if not user_id:
return jsonify({"success": False, "message": "로그인 필요"})

tx_id = secrets.token_hex(16) # 랜덤 트랜잭션 ID

payload = {
"requestType": "USER_NONE",
}
headers = {
"Authorization": f"Bearer {TOSS_API_KEY}",
"Content-Type": "application/json"
}

try:
response = requests.post(TOSS_AUTH_REQUEST_URL, headers=headers, json=payload)
result = response.json()
except Exception as e:
return jsonify({"success": False, "message": f"API 요청 실패: {e}"})

if result.get("success"):
return jsonify({
"success": True,
"authUrl": result.get("authUrl"),
"txId": result.get("txId")
})
else:
return jsonify({"success": False, "message": "토스 본인인증 실패"})
이렇게 하였는데 작동하지 않습니다 API 키가 다른건가요?
5 Replies
토스페이먼츠 BOT
⏳ 잠시만 기다려주세요! 곧 답변드리겠습니다
오류 문의일 경우 아래 정보를 미리 전달해주시면, 빠른 답변에 도움이 됩니다.
- 주문번호(orderId) : - 문의 내용 :
(img를 함께 첨부해주시면 도움이됩니다)
* 계약관련 내용은 1544-7772로 문의주세요. * 주말/공휴일에는 답변이 늦을 수 있어요.
devhub
devhubOP2mo ago
try {
const res = await fetch("/auth/verify-identity", { method: "POST" });
const data = await res.json();
if (!data.success) {
alert("본인인증을 진행할 수 없습니다.");
return;
}

// ✅ 토스 본인인증 표준창 열기
const authWindow = window.open(
data.authUrl + "?txId=" + encodeURIComponent(data.txId),
"tossAuth",
"width=500,height=700"
);

// ✅ 인증 완료 이벤트 감지 (postMessage)
window.addEventListener("message", async (event) => {
if (event.data === "TOSS_AUTH_SUCCESS") {
authWindow.close();
// 본인인증 성공 → 결제 실행
await requestTossPayment(site, keyword, selectedPayMethod);
} else if (event.data === "TOSS_AUTH_FAIL") {
authWindow.close();
alert("본인인증 실패. 결제를 진행할 수 없습니다.");
}
}, { once: true });

} catch (err) {
console.error(err);
alert("본인인증 중 오류가 발생했습니다.");
return;
}
try {
const res = await fetch("/auth/verify-identity", { method: "POST" });
const data = await res.json();
if (!data.success) {
alert("본인인증을 진행할 수 없습니다.");
return;
}

// ✅ 토스 본인인증 표준창 열기
const authWindow = window.open(
data.authUrl + "?txId=" + encodeURIComponent(data.txId),
"tossAuth",
"width=500,height=700"
);

// ✅ 인증 완료 이벤트 감지 (postMessage)
window.addEventListener("message", async (event) => {
if (event.data === "TOSS_AUTH_SUCCESS") {
authWindow.close();
// 본인인증 성공 → 결제 실행
await requestTossPayment(site, keyword, selectedPayMethod);
} else if (event.data === "TOSS_AUTH_FAIL") {
authWindow.close();
alert("본인인증 실패. 결제를 진행할 수 없습니다.");
}
}, { once: true });

} catch (err) {
console.error(err);
alert("본인인증 중 오류가 발생했습니다.");
return;
}
Kimoon Lee
Kimoon Lee2mo ago
본인인증은 저희가 지원하지 않고 있습니다. 토스코어쪽 에 문의해 주셔야 합니다. cert.support@toss.im 로 문의 주세요.
devhub
devhubOP2mo ago
아 넵 감사합니다!
토스페이먼츠 BOT
❤️ 기술문의 경험이 어떠셨나요?!
간단히 코멘트 남겨주세요! 제품 발전에 큰 힘이 됩니다.

Did you find this page helpful?