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') {