Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
provider.php
1<?php
2namespace Bitrix\Rest\OAuth;
3
4
9
11{
15 protected static $instance = null;
16
17 public static function instance()
18 {
19 if(static::$instance === null)
20 {
21 static::$instance = new static();
22 }
23
24 return static::$instance;
25 }
26
27 public function authorizeClient($clientId, $userId, $state = '')
28 {
29 if($userId > 0)
30 {
31 $additionalParams = $this->getTokenParams(array(), $userId);
32
33 $client = $this->getClient();
34 $codeInfo = $client->getCode($clientId, $state, $additionalParams);
35
36 if($codeInfo['result'])
37 {
38 return $codeInfo['result'];
39 }
40 else
41 {
42 return $codeInfo;
43 }
44 }
45
46 return false;
47 }
48
49 public function get($clientId, $scope, $additionalParams, $userId)
50 {
51 if($userId > 0)
52 {
53 $additionalParams = $this->getTokenParams($additionalParams, $userId);
54
55 $client = $this->getClient();
56 $authResult = $client->getAuth($clientId, $scope, $additionalParams);
57
58 if($authResult['result'])
59 {
60 if($authResult['result']['access_token'])
61 {
62 $authResult['result']['user_id'] = $userId;
63 $authResult['result']['client_id'] = $clientId;
64
65 Auth::storeRegisteredAuth($authResult['result']);
66 }
67
68 if (!empty($authResult['result']['date_finish_format']))
69 {
70 $dateFinish = new DateTime($authResult['result']['date_finish_format'], DATE_ATOM);
71 $authResult['result']['date_finish'] = $dateFinish->getTimestamp();
72 }
73
74 return $authResult['result'];
75 }
76 else
77 {
78 return $authResult;
79 }
80 }
81
82 return false;
83 }
84
85 protected function getClient()
86 {
87 return OAuthService::getEngine()->getClient();
88 }
89
90 protected function getTokenParams($additionalParams, $userId)
91 {
92 if(!is_array($additionalParams))
93 {
94 $additionalParams = array();
95 }
96
97 $additionalParams[Auth::PARAM_LOCAL_USER] = $userId;
98 $additionalParams[Auth::PARAM_TZ_OFFSET] = \CTimeZone::getOffset();
99 $additionalParams[Session::PARAM_SESSION] = Session::get();
100
101 return $additionalParams;
102 }
103}
static storeRegisteredAuth(array $tokenInfo)
Definition auth.php:60
authorizeClient($clientId, $userId, $state='')
Definition provider.php:27
getTokenParams($additionalParams, $userId)
Definition provider.php:90