37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
// descope_verify_magiclink.php
|
|
header('Content-Type: application/json');
|
|
|
|
$api_key = "P2wON5fy1K6kyia269VpeIzYP8oP"; // 본인 Descope API Key로 교체
|
|
$token = $_POST['token'] ?? '';
|
|
if (!$token) exit(json_encode(['status'=>'fail', 'message'=>'토큰 없음']));
|
|
|
|
$url = "https://api.descope.com/v1/auth/magiclink/verify";
|
|
$data = [ "token" => $token ];
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
"Authorization: Bearer $api_key",
|
|
"Content-Type: application/json"
|
|
]);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
$response = curl_exec($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
$resData = json_decode($response, true);
|
|
|
|
if ($code == 200 && !empty($resData['refreshJwt'])) {
|
|
echo json_encode([
|
|
'status' => 'ok',
|
|
'refreshJwt' => $resData['refreshJwt'],
|
|
'email' => $resData['user']['email'] ?? ($resData['user']['loginIds'][0] ?? '')
|
|
]);
|
|
} else {
|
|
$msg = $resData['errorDescription'] ?? '인증 실패';
|
|
echo json_encode(['status'=>'fail', 'message'=>$msg, 'raw'=>$resData]);
|
|
}
|
|
|
|
?>
|