1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
oauthservice.php
См. документацию.
1<?php
8
9namespace Bitrix\Rest;
10
11
12use Bitrix\Main\ArgumentException;
13use Bitrix\Main\Context;
14use Bitrix\Main\Localization\Loc;
15use Bitrix\Main\SystemException;
16use Bitrix\Main\Web\HttpClient;
17use Bitrix\Main\Web\Json;
18use Bitrix\Rest\OAuth\Engine;
19use Bitrix\Rest\Public\Provider;
20
21Loc::loadMessages(__FILE__);
22
23if(!defined("BITRIX_OAUTH_URL"))
24{
25// replaced \Bitrix\Main\Config\Option::get('rest', 'oauth_server', 'https://oauth.bitrix.info');
26 $defaultValue = (new Provider\OAuth\AuthorizationServerProvider())->getCurrentAuthorizationUrl();
27
28 define("BITRIX_OAUTH_URL", $defaultValue);
29}
30
31if(!defined('BITRIXREST_URL'))
32{
33 define('BITRIXREST_URL', BITRIX_OAUTH_URL);
34}
35
36
38{
39 const SERVICE_URL = BITRIXREST_URL;
40 const CLIENT_TYPE = 'B';
41
42 const REGISTER = "/oauth/register/";
43
44 protected static $engine = null;
45
49 public static function getEngine()
50 {
51 if(!static::$engine)
52 {
53 static::$engine = new Engine();
54 }
55
56 return static::$engine;
57 }
58
59 public static function register()
60 {
61 $httpClient = new HttpClient();
62
63 $queryParams = array(
64 "redirect_uri" => static::getRedirectUri(),
65 "type" => static::CLIENT_TYPE,
66 );
67
68 $memberId = \CRestUtil::getMemberId();
69 if($memberId !== null)
70 {
71 $queryParams["member_id"] = $memberId;
72 }
73
74 $queryParams = \CRestUtil::signLicenseRequest($queryParams, static::getEngine()->getLicense());
75
76 $httpResult = $httpClient->post(static::SERVICE_URL.static::REGISTER, $queryParams);
77
78 try
79 {
80 $result = Json::decode($httpResult);
81 }
82 catch(ArgumentException $e)
83 {
84 $result = array(
85 "error" => "Wrong answer from service: ".$httpResult,
86 );
87 }
88
89 if($result["error"])
90 {
91 throw new SystemException($result["error"]);
92 }
93 else
94 {
95 static::getEngine()->setAccess($result);
96 }
97 }
98
99 public static function unregister()
100 {
101 if(static::getEngine()->isRegistered())
102 {
103 static::getEngine()->clearAccess();
104 }
105 }
106
107 public static function getMemberId()
108 {
109 if(static::getEngine()->isRegistered())
110 {
111 return md5(static::getEngine()->getClientId());
112 }
113 else
114 {
115 return null;
116 }
117 }
118
119 public static function getRedirectUri()
120 {
121 $request = Context::getCurrent()->getRequest();
122 $server = Context::getCurrent()->getServer();
123
124 $host = defined('BX24_HOST_NAME') ? BX24_HOST_NAME : $server->getHttpHost();
125
126 return ($request->isHttps() ? 'https' : 'http').'://'.preg_replace("/:(443|80)$/", "", $host);
127 }
128}
if($_SERVER $defaultValue['REQUEST_METHOD']==="GET" &&!empty($RestoreDefaults) && $bizprocPerms==="W" &&check_bitrix_sessid())
Определения options.php:32
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static unregister()
Определения oauthservice.php:99
static getEngine()
Определения oauthservice.php:49
static getMemberId()
Определения oauthservice.php:107
static $engine
Определения oauthservice.php:44
const CLIENT_TYPE
Определения oauthservice.php:40
const REGISTER
Определения oauthservice.php:42
static getRedirectUri()
Определения oauthservice.php:119
const SERVICE_URL
Определения oauthservice.php:39
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
Определения action.php:3
$host
Определения mysql_to_pgsql.php:32