Files
egbim_homepage/egbim/bbs/descope_refresh_session.php
2026-07-23 16:15:57 +09:00

42 lines
1.2 KiB
PHP

<?php
session_start();
$projectId = "P2x3wl3tAgsGmSytBQ72rwABOQD"; // 대일님 Descope 프로젝트 ID
$refreshJwt = $_SESSION['refreshJwt'] ?? '';
if (!$refreshJwt) {
http_response_code(401);
echo json_encode(['status' => 'fail', 'message' => '리프레시 토큰 없음']);
exit;
}
$url = "https://api.descope.com/v1/auth/refresh";
$headers = [
"Authorization: Bearer {$projectId}:{$refreshJwt}",
"Content-Type: application/json"
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{}"); // body는 비워둬도 됨
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$data = json_decode($response, true);
// 🔄 refreshJwt도 갱신됨
$_SESSION['refreshJwt'] = $data['refreshJwt'];
echo json_encode([
'status' => 'ok',
'sessionJwt' => $data['sessionJwt']
]);
} else {
echo json_encode(['status' => 'fail', 'message' => '세션 갱신 실패', 'raw' => $response]);
}