최초 커밋
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
header('Content-Type: application/json; charset=UTF-8');
|
||||
|
||||
function set_descope_session_cookies(array $user): void {
|
||||
$expire = time() + 86400;
|
||||
$cookieOptions = [
|
||||
'expires' => $expire,
|
||||
'path' => '/',
|
||||
'samesite' => 'Lax',
|
||||
];
|
||||
|
||||
setcookie('descope_login_id', (string)($user['loginIds'][0] ?? ''), $cookieOptions);
|
||||
setcookie('descope_user_id', (string)($user['userId'] ?? ''), $cookieOptions);
|
||||
setcookie('descope_user_name', (string)($user['name'] ?? ''), $cookieOptions);
|
||||
setcookie('descope_user_email', (string)($user['email'] ?? ''), $cookieOptions);
|
||||
setcookie('descope_user_phone', (string)($user['phone'] ?? ''), $cookieOptions);
|
||||
setcookie('descope_custom_attributes', base64_encode(json_encode($user['customAttributes'] ?? [], JSON_UNESCAPED_UNICODE)), $cookieOptions);
|
||||
setcookie('descope_role_names', base64_encode(json_encode($user['roleNames'] ?? [], JSON_UNESCAPED_UNICODE)), $cookieOptions);
|
||||
}
|
||||
|
||||
$loginId = trim((string)($_POST['loginId'] ?? ''));
|
||||
$sessionJwt = trim((string)($_POST['sessionJwt'] ?? ''));
|
||||
|
||||
if ($loginId === '' || substr_count($sessionJwt, '.') !== 2) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'fail', 'message' => 'invalid session payload']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$user = [
|
||||
'userId' => trim((string)($_POST['userId'] ?? $loginId)),
|
||||
'loginIds' => [$loginId],
|
||||
'name' => trim((string)($_POST['userName'] ?? $loginId)),
|
||||
'email' => trim((string)($_POST['email'] ?? $loginId)),
|
||||
'phone' => trim((string)($_POST['phone'] ?? '')),
|
||||
'customAttributes' => [
|
||||
'company' => trim((string)($_POST['company'] ?? '')),
|
||||
'familyCompany' => trim((string)($_POST['familyCompany'] ?? '')),
|
||||
'position' => trim((string)($_POST['position'] ?? '')),
|
||||
'team' => trim((string)($_POST['team'] ?? '')),
|
||||
'familyUniqueKey' => trim((string)($_POST['familyUniqueKey'] ?? '')),
|
||||
],
|
||||
'roleNames' => array_values(array_filter([trim((string)($_POST['userRole'] ?? ''))])),
|
||||
];
|
||||
|
||||
$_SESSION['user'] = $user;
|
||||
$_SESSION['sessionJwt'] = $sessionJwt;
|
||||
set_descope_session_cookies($user);
|
||||
|
||||
echo json_encode(['status' => 'ok']);
|
||||
exit;
|
||||
?>
|
||||
Reference in New Issue
Block a user