From 83b6c41f0ba5f1223545586eacf4875a0120fe96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc?= <1536036+zoic21@users.noreply.github.com> Date: Mon, 9 Nov 2026 14:15:08 +0100 Subject: [PATCH] Utiliser la session Bearer du Core pour le Cloud Jeedom --- core/class/mail.class.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/class/mail.class.php b/core/class/mail.class.php index 7891012..4d4f3fc 100644 --- a/core/class/mail.class.php +++ b/core/class/mail.class.php @@ -124,7 +124,23 @@ public function execute($_options = null) { } $url = config::byKey('service::cloud::url') . '/service/mail'; $request_http = new com_http($url); - $request_http->setHeader(array('Content-Type: application/json', 'Autorization: ' . sha512(mb_strtolower(config::byKey('market::username')) . ':' . config::byKey('market::password')))); + $cloudToken = null; + if (is_callable(array('repo_market', 'getCloudToken'))) { + try { + $cloudToken = repo_market::getCloudToken(); + } catch (Exception $e) { + if ($e->getCode() !== 401) { + throw $e; + } + } + } + if ($cloudToken) { + if (strtolower((string) parse_url($request_http->getUrl(), PHP_URL_SCHEME)) !== 'https') { + throw new Exception(__('Le service Cloud doit utiliser HTTPS.', __FILE__)); + } + $request_http->setNoSslCheck(false); + } + $request_http->setHeader(array('Content-Type: application/json', $cloudToken ? 'Authorization: Bearer ' . $cloudToken : 'Autorization: ' . sha512(mb_strtolower(config::byKey('market::username')) . ':' . config::byKey('market::password')))); $request_http->setPost(json_encode($data)); $datas = json_decode($request_http->exec(30, 1), true); if ($datas['state'] != 'ok') {