89 lines
2.6 KiB
PHP
89 lines
2.6 KiB
PHP
<?php
|
|
// descope_verify.php
|
|
|
|
// _GNUBOARD_ 등 시스템 상수 포함 필요
|
|
include_once('../../common.php');
|
|
|
|
// POST 데이터 받기
|
|
$otp_code = trim($_POST['otp_code'] ?? '');
|
|
$email = trim($_POST['email'] ?? '');
|
|
|
|
// $email = 'sdi9429@gmail.com'; // ★ 실제 인증번호 메일 받은 주소
|
|
// $otp_code = '378484';
|
|
|
|
if (strlen($otp_code) !== 6) {
|
|
echo json_encode(['status'=>'fail', 'message'=>'잘못된 인증번호']);
|
|
exit;
|
|
}
|
|
|
|
// 1. Descope API에 검증 요청 (curl 또는 file_get_contents)
|
|
$descope_project_id = "P2wON5fy1K6kyia269VpeIzYP8oP";
|
|
$descope_api_url = "https://api.descope.com/v1/auth/otp/verify/email"; // email 인증 기준
|
|
|
|
// $data = [
|
|
// 'loginId' => $email, // 이메일 아이디
|
|
// 'code' => $otp_code, // 입력받은 6자리 코드
|
|
// ];
|
|
|
|
// $headers = [
|
|
// 'Content-Type: application/json',
|
|
// 'Accept: application/json',
|
|
// "x-descope-project-id: $descope_project_id"
|
|
// ];
|
|
|
|
// $ch = curl_init();
|
|
// curl_setopt($ch, CURLOPT_URL, $descope_api_url);
|
|
// curl_setopt($ch, CURLOPT_POST, true);
|
|
// curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
|
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
// $response = curl_exec($ch);
|
|
// $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
// curl_close($ch);
|
|
|
|
// $res_data = json_decode($response, true);
|
|
|
|
// if ($http_code === 200 && isset($res_data['user'])) {
|
|
// // 인증 성공
|
|
// echo json_encode(['status'=>'ok']);
|
|
// } else {
|
|
// // 실패, 에러 메시지 출력
|
|
// $msg = $res_data['errorDescription'] ?? '인증 실패';
|
|
// echo json_encode(['status'=>'fail', 'message'=>$msg]);
|
|
// }
|
|
|
|
|
|
|
|
$data = [
|
|
'loginId' => $email,
|
|
'code' => $otp_code,
|
|
];
|
|
$headers = [
|
|
'Content-Type: application/json',
|
|
'Authorization: Bearer ' . $descope_project_id,
|
|
];
|
|
$ch = curl_init('https://api.descope.com/v1/auth/otp/verify/email');
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
$response = curl_exec($ch);
|
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
$res_data = json_decode($response, true);
|
|
if ($http_code === 200 && isset($res_data['sessionJwt'])) {
|
|
// 인증 성공
|
|
echo json_encode([
|
|
'status'=>'ok',
|
|
'refreshJwt' => $res_data['refreshJwt'] ?? '',
|
|
]);
|
|
} else {
|
|
// 인증 실패
|
|
$msg = $res_data['errorDescription'] ?? '인증 실패';
|
|
echo json_encode(['status'=>'fail', 'message'=>$msg]);
|
|
}
|
|
exit;
|
|
?>
|