206 lines
6.3 KiB
PHP
206 lines
6.3 KiB
PHP
<?php
|
|
// header('Content-Type: application/json; charset=utf-8');
|
|
// ini_set('display_errors', 1);
|
|
// error_reporting(E_ALL);
|
|
|
|
// $email = trim($_POST['email'] ?? '');
|
|
// $password = trim($_POST['password'] ?? '');
|
|
|
|
// if (!$email || !$password) {
|
|
// echo json_encode(['status' => 'error', 'message' => '이메일 또는 비밀번호가 없습니다.']);
|
|
// exit;
|
|
// }
|
|
|
|
// $project_id = 'P2wON5fy1K6kyia269VpeIzYP8oP'; // 너의 Descope 프로젝트 ID
|
|
|
|
// $url = 'https://api.descope.com/v1/auth/password/signup';
|
|
// $data = [
|
|
// "email" => $email,
|
|
// "password" => $password
|
|
// ];
|
|
// $ch = curl_init($url);
|
|
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
// curl_setopt($ch, CURLOPT_POST, true);
|
|
// curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
|
// "loginId" => $email,
|
|
// "user" => [
|
|
// "loginId" => $email,
|
|
// "email" => $email
|
|
// ],
|
|
// "password" => $password
|
|
// ]));
|
|
// curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
// "Content-Type: application/json",
|
|
// "Authorization: Bearer $project_id"
|
|
// ]);
|
|
// $response = curl_exec($ch);
|
|
// $err = curl_error($ch);
|
|
// $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
// curl_close($ch);
|
|
|
|
// if ($http_code === 200) {
|
|
// echo json_encode(['status' => 'ok']);
|
|
// } else {
|
|
// $response_json = json_decode($response, true);
|
|
// echo json_encode([
|
|
// 'status' => 'error',
|
|
// 'message' => $response_json['errorDescription'] ?? 'Descope API 호출 실패',
|
|
// 'code' => $http_code,
|
|
// 'error' => $err
|
|
// ]);
|
|
// }
|
|
|
|
// exit;
|
|
?>
|
|
<?php
|
|
// ini_set('display_errors', 1);
|
|
// ini_set('display_startup_errors', 1);
|
|
// error_reporting(E_ALL);
|
|
// header('Content-Type: application/json; charset=utf-8');
|
|
|
|
// // $email = trim($_POST['email'] ?? '');
|
|
// // $password = trim($_POST['password'] ?? '');
|
|
// $email = 'sdi9429@gmail.com';
|
|
|
|
// // if (!$email || !$password) {
|
|
// // echo json_encode(['status' => 'error', 'message' => '이메일 또는 비밀번호가 없습니다.']);
|
|
// // exit;
|
|
// // }
|
|
// if (!$email) {
|
|
// echo json_encode(['status' => 'error', 'message' => '이메일이 없습니다.']);
|
|
// exit;
|
|
// }
|
|
|
|
// $project_id = 'P2wON5fy1K6kyia269VpeIzYP8oP'; // Descope 프로젝트 ID
|
|
|
|
// // // 1. 비밀번호 회원가입 (Password Signup)
|
|
// // $url_signup = 'https://api.descope.com/v1/auth/password/signup';
|
|
// // $signup_data = [
|
|
// // "loginId" => $email,
|
|
// // "user" => [
|
|
// // "loginId" => $email,
|
|
// // "email" => $email
|
|
// // ],
|
|
// // "password" => $password
|
|
// // ];
|
|
|
|
// // $ch = curl_init($url_signup);
|
|
// // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
// // curl_setopt($ch, CURLOPT_POST, true);
|
|
// // curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($signup_data));
|
|
// // curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
// // "Content-Type: application/json",
|
|
// // "Authorization: Bearer $project_id"
|
|
// // ]);
|
|
// // $response_signup = curl_exec($ch);
|
|
// // $err_signup = curl_error($ch);
|
|
// // $http_code_signup = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
// // curl_close($ch);
|
|
|
|
// // if ($http_code_signup !== 200) {
|
|
// // $response_json = json_decode($response_signup, true);
|
|
// // echo json_encode([
|
|
// // 'status' => 'error',
|
|
// // 'message' => $response_json['errorDescription'] ?? 'Descope 회원가입 API 호출 실패',
|
|
// // 'code' => $http_code_signup,
|
|
// // 'error' => $err_signup
|
|
// // ]);
|
|
// // exit;
|
|
// // }
|
|
|
|
// // 2. OTP 이메일 전송
|
|
// $url = "https://api.descope.com/v1/auth/otp/signup/email";
|
|
// $data = [
|
|
// "loginId" => $email, // 이메일 주소
|
|
// "email" => $email
|
|
// ];
|
|
|
|
// $ch = curl_init($url);
|
|
// 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, [
|
|
// "Content-Type: application/json",
|
|
// "Authorization: Bearer $project_id"
|
|
// ]);
|
|
// $response = curl_exec($ch);
|
|
// $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
// curl_close($ch);
|
|
|
|
// // if ($http_code === 200) {
|
|
// // echo json_encode(['status' => 'ok']);
|
|
// // } else {
|
|
// // $response_json = json_decode($response, true);
|
|
// // echo json_encode([
|
|
// // 'status' => 'error',
|
|
// // 'message' => $response_json['errorDescription'] ?? 'Descope API 호출 실패',
|
|
// // 'code' => $http_code
|
|
// // ]);
|
|
// // }
|
|
|
|
// // sessionJwt는 반드시 프론트에 넘겨야 함!
|
|
// if ($http_code === 200 && !empty($res_data['sessionJwt'])) {
|
|
// echo json_encode(['status'=>'ok', 'sessionJwt'=>$res_data['sessionJwt']]);
|
|
// } else {
|
|
// $msg = $res_data['errorDescription'] ?? 'Descope OTP 발송 실패';
|
|
// echo json_encode(['status'=>'fail', 'message'=>$msg, 'debug'=>$res_data]);
|
|
// }
|
|
|
|
// echo json_encode([
|
|
// 'status'=>'debug',
|
|
// 'raw'=> $response, // $response: curl_exec 결과
|
|
// 'php_error'=> error_get_last()
|
|
// ]);
|
|
|
|
// exit;
|
|
?>
|
|
<?php
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
ini_set('display_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
$email = trim($_POST['email'] ?? '');
|
|
|
|
// 생략 가능: $email = 'test123@test.com';
|
|
|
|
$project_id = 'P2wON5fy1K6kyia269VpeIzYP8oP'; // 실제 프로젝트 ID로 변경
|
|
|
|
$url = "https://api.descope.com/v1/auth/otp/signup/email";
|
|
$data = [
|
|
"loginId" => $email,
|
|
"email" => $email
|
|
];
|
|
|
|
$ch = curl_init($url);
|
|
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, [
|
|
"Content-Type: application/json",
|
|
"Authorization: Bearer $project_id"
|
|
]);
|
|
$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['maskedEmail'])) {
|
|
// 성공 케이스
|
|
echo json_encode(['status' => 'ok', 'maskedEmail' => $res_data['maskedEmail']]);
|
|
} else {
|
|
// 실패 케이스
|
|
$msg = $res_data['errorDescription'] ?? 'Descope OTP 발송 실패';
|
|
echo json_encode([
|
|
'status' => 'fail',
|
|
'message' => $msg,
|
|
'debug' => $res_data
|
|
]);
|
|
}
|
|
exit;
|
|
|
|
?>
|
|
|
|
|
|
|