Initial commit: Auth Server Base
This commit is contained in:
36
local/modules/conmed.authserver/lib/webhook.php
Normal file
36
local/modules/conmed.authserver/lib/webhook.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Conmed\Authserver;
|
||||
|
||||
use Bitrix\Main\Config\Option;
|
||||
use Bitrix\Main\Web\HttpClient;
|
||||
|
||||
class Webhook {
|
||||
public static function sendDelete($userId) {
|
||||
$rawList = Option::get("conmed.authserver", "client_list");
|
||||
$lines = explode("\n", str_replace("\r", "", $rawList));
|
||||
|
||||
foreach($lines as $line) {
|
||||
$pair = explode(":", trim($line), 3);
|
||||
if(count($pair) < 3) continue;
|
||||
|
||||
$clientId = trim($pair[0]);
|
||||
$secret = trim($pair[1]); // Здесь хеш
|
||||
$domain = trim($pair[2], " /");
|
||||
|
||||
// Формируем URL контроллера на удаленном сайте
|
||||
$url = $domain . "/bitrix/services/main/ajax.php?action=conmed:sso.api.webhook.delete";
|
||||
|
||||
// Подписываем запрос (используем часть хеша секрета как ключ)
|
||||
$signature = hash_hmac('sha256', $userId, $secret);
|
||||
|
||||
//$http = new HttpClient(['sslVerify' => false, 'socketTimeout' => 3]);
|
||||
$isSslVerify = \Bitrix\Main\Config\Option::get("conmed.authserver", "ssl_verify", "Y") === "Y";
|
||||
$http = new HttpClient(['sslVerify' => $isSslVerify, 'socketTimeout' => 3]);
|
||||
|
||||
$http->setHeader('X-SSO-Signature', $signature);
|
||||
|
||||
// Отправляем асинхронно (короткий таймаут), чтобы не вешать админку
|
||||
$http->post($url, ['user_id' => $userId, 'client_id' => $clientId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user