65 lines
2.4 KiB
PHP
65 lines
2.4 KiB
PHP
<?php
|
|
require_once dirname(__DIR__, 4) . '/auth/common.php';
|
|
|
|
auth_session_start_if_needed();
|
|
header('Content-Type: application/json; charset=UTF-8');
|
|
|
|
$loginId = trim((string) ($_POST['loginId'] ?? ''));
|
|
$sessionUser = $_SESSION['user'] ?? [];
|
|
$sessionLoginId = trim((string) ($sessionUser['loginIds'][0] ?? ''));
|
|
|
|
if ($loginId !== '' && $sessionLoginId !== '' && strcasecmp($loginId, $sessionLoginId) === 0) {
|
|
echo json_encode(['status' => 'ok', 'user' => auth_normalize_user($sessionUser)]);
|
|
exit;
|
|
}
|
|
|
|
$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';
|
|
|
|
$url = 'https://api.descope.com/v2/mgmt/user/search';
|
|
$payload = json_encode([
|
|
'loginId' => $loginId,
|
|
'limit' => 1,
|
|
]);
|
|
|
|
$headers = [
|
|
"Authorization: Bearer $management_key",
|
|
'Content-Type: application/json',
|
|
];
|
|
|
|
$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 = $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]);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
echo json_encode(['status' => 'fail', 'message' => '사용자를 찾을 수 없음', 'code' => $http_code]);
|