BARON-SSO 로그인 연동

This commit is contained in:
root
2026-07-27 17:23:52 +09:00
parent bf5e694571
commit ac5823234e
44 changed files with 1804 additions and 695 deletions
+27 -56
View File
@@ -1,66 +1,38 @@
<?php
// header('Content-Type: application/json');
require_once dirname(__DIR__, 4) . '/auth/common.php';
// $management_key = 'P2wON5fy1K6kyia269VpeIzYP8oP:K2ycqpjeh1voPBdxXxzB3ScZOQ6v9aiLmU2cIj70X1H8Kcoz0KWfCWmofUwAsAkJroXA8QC';
// $loginId = $_POST['loginId'] ?? '';
auth_session_start_if_needed();
header('Content-Type: application/json; charset=UTF-8');
// $url = "https://api.descope.com/v2/mgmt/user/search";
// $payload = json_encode([
// "loginId" => $loginId,
// "limit" => 1
// ]);
$loginId = trim((string) ($_POST['loginId'] ?? ''));
$sessionUser = $_SESSION['user'] ?? [];
$sessionLoginId = trim((string) ($sessionUser['loginIds'][0] ?? ''));
// $headers = [
// "Authorization: Bearer $management_key",
// "Content-Type: application/json"
// ];
if ($loginId !== '' && $sessionLoginId !== '' && strcasecmp($loginId, $sessionLoginId) === 0) {
echo json_encode(['status' => 'ok', 'user' => auth_normalize_user($sessionUser)]);
exit;
}
// $ch = curl_init($url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// $response = curl_exec($ch);
// $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// curl_close($ch);
// if ($http_code === 200) {
// $res = json_decode($response, true);
// if (!empty($res['users'][0])) {
// // ✅ 먼저 $user에 복사
// $user = $res['users'][0];
// // ✅ 값이 없으면 테스트용 기본값 삽입
// $user['name'] = $user['name'] ?: '홍길동';
// $user['phone'] = $user['phone'] ?: '01012345678';
// $user['customAttributes']['company'] = $user['customAttributes']['company'] ?? '한맥ENG';
// $user['customAttributes']['team'] = $user['customAttributes']['team'] ?? '설계팀';
// $user['customAttributes']['employeeId'] = $user['customAttributes']['employeeId'] ?? 'HM2024';
// // ✅ 수정된 $user 사용
// echo json_encode(['status' => 'ok', 'user' => $user]);
// } else {
// echo json_encode(['status' => 'fail', 'message' => '사용자를 찾을 수 없음']);
// }
// } else {
// echo json_encode(['status' => 'fail', 'message' => 'Descope API 오류', 'code' => $http_code]);
// }
?>
<?php
header('Content-Type: application/json');
$cookieUser = auth_baron_user_from_cookies();
if ($loginId !== '' && $cookieUser !== null) {
$cookieLoginId = trim((string) ($cookieUser['loginIds'][0] ?? ''));
if ($cookieLoginId !== '' && strcasecmp($loginId, $cookieLoginId) === 0) {
echo json_encode(['status' => 'ok', 'user' => $cookieUser]);
exit;
}
}
$management_key = 'P2wON5fy1K6kyia269VpeIzYP8oP:K32l5ORmzy32OvaaPvpdZsMY3JmKQb7a3vvrl10PgjlJUGk3K7EssMH3uW5VGQSbrgtEdPj';
$loginId = $_POST['loginId'] ?? '';
$url = "https://api.descope.com/v2/mgmt/user/search";
$url = 'https://api.descope.com/v2/mgmt/user/search';
$payload = json_encode([
"loginId" => $loginId,
"limit" => 1
'loginId' => $loginId,
'limit' => 1,
]);
$headers = [
"Authorization: Bearer $management_key",
"Content-Type: application/json"
'Content-Type: application/json',
];
$ch = curl_init($url);
@@ -76,18 +48,17 @@ if ($http_code === 200) {
if (!empty($res['users'][0])) {
$user = $res['users'][0];
// ✅ 실제 값이 있으면 그대로 사용, 없으면 빈 문자열
$user['name'] = $user['name'] ?? '';
$user['phone'] = $user['phone'] ?? '';
$user['customAttributes']['company'] = $user['customAttributes']['company'] ?? '';
$user['customAttributes']['familyCompany'] = $user['customAttributes']['familyCompany'] ?? '';
$user['customAttributes']['team'] = $user['customAttributes']['team'] ?? '';
$user['customAttributes']['employeeId'] = $user['customAttributes']['employeeId'] ?? '';
$user['customAttributes']['familyUniqueKey'] = $user['customAttributes']['familyUniqueKey'] ?? '';
echo json_encode(['status' => 'ok', 'user' => $user]);
} else {
echo json_encode(['status' => 'fail', 'message' => '사용자를 찾을 수 없음']);
exit;
}
} else {
echo json_encode(['status' => 'fail', 'message' => 'Descope API 오류', 'code' => $http_code]);
}
echo json_encode(['status' => 'fail', 'message' => '사용자를 찾을 수 없음', 'code' => $http_code]);