1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
provider.php
См. документацию.
1<?php
2
3namespace Bitrix\Rest\OAuth;
4
5use Bitrix\Main\SystemException;
6use Bitrix\Rest\AuthProviderInterface;
7use Bitrix\Rest\Event\Session;
8use Bitrix\Rest\OAuthService;
9use Bitrix\Main\Type\DateTime;
10
11class Provider implements AuthProviderInterface
12{
16 protected static $instance = null;
17
18 public static function instance()
19 {
20 if(static::$instance === null)
21 {
22 static::$instance = new static();
23 }
24
25 return static::$instance;
26 }
27
28 public function authorizeClient($clientId, $userId, $state = '')
29 {
30 if($userId > 0)
31 {
32 $additionalParams = $this->getTokenParams(array(), $userId);
33
34 $client = $this->getClient();
35 $codeInfo = $client->getCode($clientId, $state, $additionalParams);
36
37 if($codeInfo['result'])
38 {
39 return $codeInfo['result'];
40 }
41 else
42 {
43 return $codeInfo;
44 }
45 }
46
47 return false;
48 }
49
50 public function get($clientId, $scope, $additionalParams, $userId)
51 {
52 if($userId > 0)
53 {
54 $additionalParams = $this->getTokenParams($additionalParams, $userId);
55
56 $client = $this->getClient();
57 $authResult = $client->getAuth($clientId, $scope, $additionalParams);
58
59 if($authResult['result'])
60 {
61 if($authResult['result']['access_token'])
62 {
63 $authResult['result']['user_id'] = $userId;
64 $authResult['result']['client_id'] = $clientId;
65
66 Auth::storeRegisteredAuth($authResult['result']);
67 }
68
69 if (!empty($authResult['result']['date_finish_format']))
70 {
71 $dateFinish = new DateTime($authResult['result']['date_finish_format'], DATE_ATOM);
72 $authResult['result']['date_finish'] = $dateFinish->getTimestamp();
73 }
74
75 return $authResult['result'];
76 }
77 else
78 {
79 return $authResult;
80 }
81 }
82
83 return false;
84 }
85
86 protected function getClient()
87 {
88 if (!OAuthService::getEngine()->isRegistered())
89 {
90 try
91 {
93 }
94 catch (SystemException)
95 {
96 }
97 }
98
99 return OAuthService::getEngine()->getClient();
100 }
101
102 protected function getTokenParams($additionalParams, $userId)
103 {
104 if(!is_array($additionalParams))
105 {
106 $additionalParams = array();
107 }
108
109 $additionalParams[Auth::PARAM_LOCAL_USER] = $userId;
110 $additionalParams[Auth::PARAM_TZ_OFFSET] = \CTimeZone::getOffset();
111 $additionalParams[Session::PARAM_SESSION] = Session::get();
112
113 return $additionalParams;
114 }
115}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static get()
Определения currentuser.php:33
static storeRegisteredAuth(array $tokenInfo)
Определения auth.php:62
const PARAM_LOCAL_USER
Определения auth.php:30
const PARAM_TZ_OFFSET
Определения auth.php:31
static instance()
Определения provider.php:18
authorizeClient($clientId, $userId, $state='')
Определения provider.php:28
getClient()
Определения provider.php:86
getTokenParams($additionalParams, $userId)
Определения provider.php:102
static $instance
Определения provider.php:16
static getEngine()
Определения oauthservice.php:49
static register()
Определения oauthservice.php:59
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$clientId
Определения seo_client.php:18