1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
google.php
См. документацию.
1<?
2
3use \Bitrix\Main\Web\HttpClient;
7
9
11{
12 public const ID = "GoogleOAuth";
13 const LOGIN_PREFIX = "G_";
14
16 protected $entityOAuth = null;
17
22 public function getEntityOAuth($code = false)
23 {
24 if(!$this->entityOAuth)
25 {
26 $this->entityOAuth = new CGoogleOAuthInterface();
27 }
28
29 if($code !== false)
30 {
31 $this->entityOAuth->setCode($code);
32 }
33
34 return $this->entityOAuth;
35 }
36
37 public function GetSettings()
38 {
39 return [
40 ["google_appid", GetMessage("socserv_google_client_id"), "", ["text", 40]],
41 ["google_appsecret", GetMessage("socserv_google_client_secret"), "", ["text", 40]],
42 ['google_app_api_key', GetMessage('socserv_google_api_key'), '', ['text', 40]],
43 [
44 'note' => getMessage(
45 'socserv_google_note_2_MSGVER_1',
46 [
47 '#URL#' => $this->getEntityOAuth()->getRedirectUri(),
48 '#MAIL_URL#' => \CHttp::urn2uri('/bitrix/tools/mail_oauth.php'),
49 ]
50 ),
51 ],
52 ];
53 }
54
55 public function CheckSettings()
56 {
57 return self::GetOption('google_appid') !== ''
58 && self::GetOption('google_appsecret') !== '';
59 }
60
61
62 public function GetFormHtml($arParams)
63 {
64 $url = static::getUrl('opener', null, $arParams);
65
66 $isForIntranet = $params['FOR_INTRANET'] ?? false;
67 if ($isForIntranet)
68 {
69 return array("ON_CLICK" => 'onclick="BX.util.popup(\''.htmlspecialcharsbx(CUtil::JSEscape($url)).'\', 580, 400)"');
70 }
71
72 $phrase = $isForIntranet ? GetMessage("socserv_google_form_note_intranet") : GetMessage("socserv_google_form_note");
73
74 return '<a href="javascript:void(0)" onclick="BX.util.popup(\''.htmlspecialcharsbx(CUtil::JSEscape($url)).'\', 580, 400)" class="bx-ss-button google-button"></a><span class="bx-spacer"></span><span>'.$phrase.'</span>';
75 }
76
77 public function GetOnClickJs($arParams)
78 {
79 $url = static::getUrl('opener', null, $arParams);
80 return "BX.util.popup('".CUtil::JSEscape($url)."', 580, 400)";
81 }
82
83 public function getUrl($location = 'opener', $addScope = null, $arParams = array())
84 {
85 $this->entityOAuth = $this->getEntityOAuth();
86
87 if ($this->userId === null)
88 {
89 $this->entityOAuth->setRefreshToken("skip");
90 }
91
92 if ($addScope !== null)
93 {
94 $this->entityOAuth->addScope($addScope);
95 }
96
97 $removeParams = [
98 'logout',
99 'auth_service_error',
100 'auth_service_id',
101 'backurl',
102 'serviceName',
103 'hitHash',
104 ];
105
106 if (IsModuleInstalled('bitrix24') && defined('BX24_HOST_NAME'))
107 {
108 $redirect_uri = static::getControllerUrl()."/redirect.php";
109 $state = $this->getEntityOAuth()->getRedirectUri()."?check_key=".\CSocServAuthManager::getUniqueKey()."&state=";
110 $backurl = $GLOBALS["APPLICATION"]->GetCurPageParam('', $removeParams);
111 $state .= urlencode('provider='.static::ID.
112 "&state=".urlencode("backurl=".urlencode($backurl)
113 .'&mode='.$location.(isset($arParams['BACKURL'])
114 ? '&redirect_url='.urlencode($arParams['BACKURL'])
115 : '')
116 ));
117 }
118 else
119 {
120 $state = 'provider='.static::ID.'&site_id='.SITE_ID
121 .'&backurl='.urlencode($GLOBALS["APPLICATION"]->GetCurPageParam('check_key='.\CSocServAuthManager::getUniqueKey(), $removeParams))
122 .'&mode='.$location.(isset($arParams['BACKURL'])
123 ? '&redirect_url='.urlencode($arParams['BACKURL'])
124 : '')
125 ;
126 $redirect_uri = $this->getEntityOAuth()->getRedirectUri();
127 }
128
129 return $this->entityOAuth->GetAuthUrl($redirect_uri, $state, $arParams['APIKEY'] ?? '');
130 }
131
132 public function getStorageToken()
133 {
134 $accessToken = null;
135 $userId = intval($this->userId);
136 if($userId > 0)
137 {
138 $dbSocservUser = \Bitrix\Socialservices\UserTable::getList([
139 'filter' => ['=USER_ID' => $userId, "=EXTERNAL_AUTH_ID" => static::ID],
140 'select' => ["OATOKEN", "REFRESH_TOKEN", "OATOKEN_EXPIRES"]
141 ]);
142 if($arOauth = $dbSocservUser->fetch())
143 {
144 $accessToken = $arOauth["OATOKEN"];
145
146 if(empty($accessToken) || ((intval($arOauth["OATOKEN_EXPIRES"]) > 0) && (intval($arOauth["OATOKEN_EXPIRES"] < intval(time())))))
147 {
148 if(isset($arOauth['REFRESH_TOKEN']))
149 {
150 $this->getEntityOAuth()->getNewAccessToken($arOauth['REFRESH_TOKEN'], $userId, true);
151 }
152
153 if(($accessToken = $this->getEntityOAuth()->getToken()) === false)
154 {
155 return null;
156 }
157 }
158 }
159 }
160
161 return $accessToken;
162 }
163
164 public function prepareUser($arGoogleUser, $short = false)
165 {
166 $first_name = "";
167 $last_name = "";
168 if(is_array($arGoogleUser['name']))
169 {
170 $first_name = $arGoogleUser['name']['givenName'];
171 $last_name = $arGoogleUser['name']['familyName'];
172 }
173 elseif(!empty($arGoogleUser['name']))
174 {
175 $aName = explode(" ", $arGoogleUser['name']);
176 if(!empty($arGoogleUser['given_name']))
177 {
178 $first_name = $arGoogleUser['given_name'];
179 }
180 else
181 {
182 $first_name = $aName[0];
183 }
184
185 if(!empty($arGoogleUser['family_name']))
186 {
187 $last_name = $arGoogleUser['family_name'];
188 }
189 elseif(!empty($aName[1]))
190 {
191 $last_name = $aName[1];
192 }
193 }
194
195 $id = $arGoogleUser['id'] ?? $arGoogleUser['sub'];
196 $email = $arGoogleUser['email'];
197
198 if(!empty($arGoogleUser['email']))
199 {
200 $dbRes = \Bitrix\Main\UserTable::getList(array(
201 'filter' => array(
202 '=EXTERNAL_AUTH_ID' => 'socservices',
203 '=XML_ID' => $email,
204 ),
205 'select' => array('ID'),
206 'limit' => 1
207 ));
208 if($dbRes->fetch())
209 {
210 $id = $email;
211 }
212 }
213
214 $arFields = [
215 'EXTERNAL_AUTH_ID' => static::ID,
216 'XML_ID' => $id,
217 'LOGIN' => static::LOGIN_PREFIX.$id,
218 'EMAIL' => $email,
219 'NAME'=> $first_name,
220 'LAST_NAME'=> $last_name,
221 'OATOKEN' => $this->entityOAuth->getToken(),
222 'OATOKEN_EXPIRES' => $this->entityOAuth->getAccessTokenExpires(),
223 'REFRESH_TOKEN' => $this->entityOAuth->getRefreshToken(),
224 ];
225
226 if(!empty($arGoogleUser['gender']))
227 {
228 if($arGoogleUser['gender'] === 'male')
229 {
230 $arFields["PERSONAL_GENDER"] = 'M';
231 }
232 elseif($arGoogleUser['gender'] === 'female')
233 {
234 $arFields["PERSONAL_GENDER"] = 'F';
235 }
236 }
237
238 if(!$short && isset($arGoogleUser['picture']) && $this->CheckPhotoURI($arGoogleUser['picture']))
239 {
240 $arGoogleUser['picture'] = preg_replace("/\?.*$/", '', $arGoogleUser['picture']);
241 $arPic = false;
242 if ($arGoogleUser['picture'])
243 {
244 $temp_path = CFile::GetTempName('', sha1($arGoogleUser['picture']));
245
246 $http = new HttpClient();
247 $http->setPrivateIp(false);
248 if($http->download($arGoogleUser['picture'], $temp_path))
249 {
250 $arPic = CFile::MakeFileArray($temp_path);
251 }
252 }
253
254 if($arPic)
255 {
256 $arFields["PERSONAL_PHOTO"] = $arPic;
257 }
258 }
259
260 $arFields["PERSONAL_WWW"] = $arGoogleUser['link'] ?? $arGoogleUser['url'];
261
262 if(!empty(SITE_ID))
263 {
264 $arFields["SITE_ID"] = SITE_ID;
265 }
266
267 return $arFields;
268 }
269
270 public function Authorize()
271 {
272 global $APPLICATION;
273 $APPLICATION->RestartBuffer();
274
275 $bSuccess = false;
276 $bProcessState = false;
277
278 $authError = SOCSERV_AUTHORISATION_ERROR;
279
280 if(!empty($_REQUEST["code"]) && CSocServAuthManager::CheckUniqueKey())
281 {
282 $this->getEntityOAuth()->setCode($_REQUEST["code"]);
283
284 $bProcessState = true;
285
286 if($this->getEntityOAuth()->GetAccessToken() !== false)
287 {
288 $arGoogleUser = $this->getEntityOAuth()->GetCurrentUser();
289
290 if(is_array($arGoogleUser) && !isset($arGoogleUser["error"]))
291 {
292 $arFields = $this->prepareUser($arGoogleUser);
293 $authError = $this->AuthorizeUser($arFields);
294 }
295 }
296 }
297
298 if(!$bProcessState)
299 {
300 unset($_REQUEST["state"]);
301 }
302
303 $bSuccess = $authError === true;
304
305 $aRemove = ["logout", "auth_service_error", "auth_service_id", "code", "error_reason", "error", "error_description", "check_key", "current_fieldset"];
306 $mode = null;
307
308 if($bSuccess)
309 {
310 CSocServUtil::checkOAuthProxyParams();
311
312 $url = ($APPLICATION->GetCurDir() === "/login/") ? "" : $APPLICATION->GetCurDir();
313 $mode = 'opener';
314 $addParams = true;
315 if(isset($_REQUEST["state"]))
316 {
317 $arState = array();
318 parse_str($_REQUEST["state"], $arState);
319
320 if(isset($arState['backurl']) || isset($arState['redirect_url']))
321 {
322 $url = !empty($arState['redirect_url']) ? $arState['redirect_url'] : $arState['backurl'];
323 if (!str_starts_with($url, "#"))
324 {
325 $parseUrl = parse_url($url);
326
327 $urlPath = $parseUrl["path"];
328 $arUrlQuery = explode('&', $parseUrl["query"]);
329
330 foreach($arUrlQuery as $key => $value)
331 {
332 foreach($aRemove as $param)
333 {
334 if (str_starts_with($value, $param . "="))
335 {
336 unset($arUrlQuery[$key]);
337 break;
338 }
339 }
340 }
341
342 $url = (!empty($arUrlQuery)) ? $urlPath . '?' . implode("&", $arUrlQuery) : $urlPath;
343 }
344 else
345 {
346 $addParams = false;
347 }
348 }
349
350 if(isset($arState['mode']))
351 {
352 $mode = $arState['mode'];
353 }
354 }
355 }
356
357 if ($authError === SOCSERV_REGISTRATION_DENY)
358 {
359 $url = (preg_match("/\?/", $url)) ? $url.'&' : $url.'?';
360 $url .= 'auth_service_id='.static::ID.'&auth_service_error='.SOCSERV_REGISTRATION_DENY;
361 }
362 elseif ($bSuccess !== true)
363 {
364 $url = (isset($urlPath)) ? $urlPath.'?auth_service_id='.static::ID.'&auth_service_error='.$authError : $APPLICATION->GetCurPageParam(('auth_service_id='.static::ID.'&auth_service_error='.$authError), $aRemove);
365 }
366
367 if($addParams && CModule::IncludeModule("socialnetwork") && mb_strpos($url, "current_fieldset=") === false)
368 {
369 $url = (preg_match("/\?/", $url)) ? $url."&current_fieldset=SOCSERV" : $url."?current_fieldset=SOCSERV";
370 }
371
372 $url = CUtil::JSEscape($url);
373
374 if ($bSuccess && $mode === self::MOBILE_MODE)
375 {
376 $this->onAfterMobileAuth();
377 }
378 else
379 {
380 $this->onAfterWebAuth($addParams, $mode, $url);
381 }
382
383 CMain::FinalActions();
384 }
385
386 public function setUser($userId)
387 {
388 $this->getEntityOAuth()->setUser($userId);
389 }
390
391 public function getFriendsList($limit, &$next)
392 {
393 $res = [];
394
395 if($this->getEntityOAuth()->GetAccessToken() !== false)
396 {
397 $res = $this->getEntityOAuth()->getCurrentUserFriends($limit, $next);
398
399 foreach($res as $key => $contact)
400 {
401 $contact['uid'] = $contact['email'];
402
403 $arName = $contact['name'];
404
405 $contact['first_name'] = trim($arName['givenName']);
406 $contact['last_name'] = trim($arName['familyName']);
407 $contact['second_name'] = trim($arName['additionalName']);
408
409 if(!$contact['first_name'] && !$contact['last_name'])
410 {
411 $contact['first_name'] = $contact['uid'];
412 }
413
414 $res[$key] = $contact;
415 }
416 }
417
418 return $res;
419 }
420}
421
422class CGoogleOAuthInterface extends CSocServOAuthTransport
423{
424 const SERVICE_ID = "GoogleOAuth";
425
426 public const CERTS_URL = "https://www.googleapis.com/oauth2/v3/certs";
427 public const JWT_ALG = ["RS256"];
428
429 const AUTH_URL = "https://accounts.google.com/o/oauth2/auth";
430 const TOKEN_URL = "https://accounts.google.com/o/oauth2/token";
431 const CONTACTS_URL = "https://www.googleapis.com/oauth2/v1/userinfo";
432 const FRIENDS_URL = "https://www.google.com/m8/feeds/contacts/default/full";
433 const TOKENINFO_URL = "https://www.googleapis.com/oauth2/v2/tokeninfo";
434
435 const REDIRECT_URI = "/bitrix/tools/oauth/google.php";
436
438 'https://www.googleapis.com/auth/userinfo.email',
439 'https://www.googleapis.com/auth/userinfo.profile',
440 );
441
442 protected $scope = array();
443
444 protected $arResult = array();
445
446 protected ?string $idTokenAuth = null;
447 protected ?array $fetchedPublicKeys = null;
448
449 public function __construct($appID = false, $appSecret = false, $code = false)
450 {
451 if($appID === false)
452 {
453 $appID = trim(CSocServGoogleOAuth::GetOption("google_appid"));
454 }
455
456 if($appSecret === false)
457 {
458 $appSecret = trim(CSocServGoogleOAuth::GetOption("google_appsecret"));
459 }
460
461 $this->scope = $this->standardScope;
462
463 $this->checkSavedScope();
464
465 parent::__construct($appID, $appSecret, $code);
466 }
467
468 protected function getOptionNameForScopes(): string
469 {
470 return 'saved_scope_'.static::SERVICE_ID;
471 }
472
473 protected function checkSavedScope(): void
474 {
475 $savedScope = \Bitrix\Main\Config\Option::get('socialservices', $this->getOptionNameForScopes(), '');
476 if($savedScope)
477 {
478 $savedScope = unserialize($savedScope, ['allowed_classes' => false]);
479 if(is_array($savedScope))
480 {
481 $this->scope = array_merge($this->scope, $savedScope);
482 }
483 }
484 }
485
486 protected function saveScope(): void
487 {
488 $scope = array_unique(array_diff($this->scope, $this->standardScope));
489 \Bitrix\Main\Config\Option::set('socialservices', $this->getOptionNameForScopes(), serialize($scope));
490 }
491
492 public function addScope($scope)
493 {
494 parent::addScope($scope);
495
496 $this->saveScope();
497
498 return $this;
499 }
500
501 public function removeScope(string $scope): void
502 {
503 parent::removeScope($scope);
504
505 $this->saveScope();
506 }
507
508 public function getScopeEncode()
509 {
510 return implode('+', array_map('urlencode', array_unique($this->getScope())));
511 }
512
513 public function getResult()
514 {
515 return $this->arResult;
516 }
517
518 public function getError()
519 {
520 return is_array($this->arResult) && isset($this->arResult['error'])
521 ? $this->arResult['error']
522 : '';
523 }
524
525 public function GetAuthUrl($redirect_uri, $state = '', $apiKey = '')
526 {
527 return static::AUTH_URL.
528 "?client_id=".urlencode($this->appID).
529 "&redirect_uri=".urlencode($redirect_uri).
530 "&scope=".$this->getScopeEncode().
531 "&response_type=code".
532 "&access_type=offline".
533 ($this->refresh_token <> '' ? '' : '&approval_prompt=force').
534 ($state <> '' ? '&state='.urlencode($state) : '').
535 ($apiKey !== '' ? '&key=' . urlencode($apiKey) : '')
536 ;
537 }
538
539 public function setIdTokenAuth(string $tokenId): void
540 {
541 $this->idTokenAuth = $tokenId;
542 }
543
544 private function fetchPublicKeys(): ?array
545 {
546 if ($this->fetchedPublicKeys)
547 {
548 return $this->fetchedPublicKeys;
549 }
550
551 try
552 {
553 $publicKeys = $this->getDecodedJson(self::CERTS_URL);
554 if (empty($publicKeys['keys']) || count($publicKeys['keys']) < 1)
555 {
556 return null;
557 }
558
559 $parsedPublicKeys = JWK::parseKeySet($publicKeys['keys']);
560 foreach ($parsedPublicKeys as $keyId => $publicKey)
561 {
562 $details = openssl_pkey_get_details($publicKey);
563 $this->fetchedPublicKeys[$keyId] = $details['key'];
564 }
565
566 return $this->fetchedPublicKeys;
567 }
568 catch (\Exception $e)
569 {
570 }
571
572 return null;
573 }
574
575 private function decodeIdentityToken(string $identityToken): array
576 {
577 $publicKeys = $this->fetchPublicKeys();
578 if ($publicKeys === null)
579 {
580 return [];
581 }
582
583 try
584 {
585 return (array)JWT::decode($identityToken, $publicKeys, self::JWT_ALG);
586 }
587 catch (UnexpectedValueException $exception)
588 {
589 return [];
590 }
591 }
592
593 public function GetAccessToken($redirect_uri = false)
594 {
595 $tokens = $this->getStorageTokens();
596
597 if(is_array($tokens))
598 {
599 $this->access_token = $tokens["OATOKEN"];
600 $this->accessTokenExpires = $tokens["OATOKEN_EXPIRES"];
601
602 if(!$this->code)
603 {
604 if($this->checkAccessToken())
605 {
606 return true;
607 }
608 elseif(isset($tokens["REFRESH_TOKEN"]))
609 {
610 if($this->getNewAccessToken($tokens["REFRESH_TOKEN"], $this->userId, true))
611 {
612 return true;
613 }
614 }
615 }
616
617 $this->deleteStorageTokens();
618 }
619
620 if($this->code === false)
621 {
622 return false;
623 }
624
625 if($redirect_uri === false)
626 {
627 if(IsModuleInstalled('bitrix24') && defined('BX24_HOST_NAME'))
628 {
629 $redirect_uri = \CSocServGoogleOAuth::getControllerUrl()."/redirect.php";
630 }
631 else
632 {
633 $redirect_uri = $this->getRedirectUri();
634 }
635 }
636
637 $authParams = [
638 "client_id" => $this->appID,
639 "code" => $this->code,
640 "redirect_uri" => $redirect_uri,
641 "grant_type" => "authorization_code",
642 "client_secret" => $this->appSecret,
643 ];
644
645 $this->arResult = $this->getDecodedJson(static::TOKEN_URL, $authParams);
646
647 if(isset($this->arResult["access_token"]) && $this->arResult["access_token"] <> '')
648 {
649 if(isset($this->arResult["refresh_token"]) && $this->arResult["refresh_token"] <> '')
650 {
651 $this->refresh_token = $this->arResult["refresh_token"];
652 }
653 $this->access_token = $this->arResult["access_token"];
654 $this->accessTokenExpires = $this->arResult["expires_in"] + time();
655
656 $_SESSION["OAUTH_DATA"] = array(
657 "OATOKEN" => $this->access_token,
658 "OATOKEN_EXPIRES" => $this->accessTokenExpires,
659 "REFRESH_TOKEN" => $this->refresh_token,
660 );
661
662 return true;
663 }
664 return false;
665 }
666
667 public function GetCurrentUser()
668 {
669 if ($this->idTokenAuth)
670 {
671 $identity = $this->decodeIdentityToken($this->idTokenAuth);
672
673 return $identity ?: false;
674 }
675
676 if($this->access_token === false)
677 return false;
678
679 $result = $this->getDecodedJson(static::CONTACTS_URL.'?access_token='.urlencode($this->access_token));
680
681 if ($result)
682 {
683 $result["access_token"] = $this->access_token;
684 $result["refresh_token"] = $this->refresh_token;
685 $result["expires_in"] = $this->accessTokenExpires;
686 }
687
688 return $result;
689 }
690
691 public function GetAppInfo()
692 {
693 if ($this->idTokenAuth)
694 {
695 $identity = $this->decodeIdentityToken($this->idTokenAuth);
696 if (empty($identity['aud']))
697 {
698 return false;
699 }
700
701 return [
702 'id' => $identity['aud'],
703 ];
704 }
705 if ($this->access_token === false)
706 {
707 return false;
708 }
709
710 $result = $this->getDecodedJson(static::TOKENINFO_URL.'?access_token='.urlencode($this->access_token));
711
712 if ($result && $result["audience"])
713 {
714 $result["id"] = $result["audience"];
715 }
716
717 return $result;
718 }
719
720 public function GetCurrentUserFriends($limit, &$next)
721 {
722 if($this->access_token === false)
723 return false;
724
725 $http = new HttpClient();
726 $http->setHeader('GData-Version', '3.0');
727 $http->setHeader('Authorization', 'Bearer '.$this->access_token);
728
729 $url = static::FRIENDS_URL.'?';
730
731 $limit = (int)$limit;
732 $next = (int)$next;
733
734 if ($limit > 0)
735 {
736 $url .= '&max-results='.$limit;
737 }
738
739 if ($next > 0)
740 {
741 $url .= '&start-index='.$next;
742 }
743
744 $result = $http->get($url);
745
746 if((int)$http->getStatus() === 200)
747 {
748 $obXml = new \CDataXML();
749 if($obXml->loadString($result))
750 {
751 $tree = $obXml->getTree();
752
753 $total = $tree->elementsByName("totalResults");
754 $total = (int)$total[0]->textContent();
755
756 $limitNode = $tree->elementsByName("itemsPerPage");
757 $next += (int)$limitNode[0]->textContent();
758
759 if($next >= $total)
760 {
761 $next = '__finish__';
762 }
763
764 $arFriends = array();
765 $arEntries = $tree->elementsByName('entry');
766 foreach($arEntries as $entry)
767 {
768 $arEntry = array();
769 $entryChildren = $entry->children();
770
771 foreach ($entryChildren as $child)
772 {
773 $tag = $child->name();
774
775 switch($tag)
776 {
777 case 'category':
778 case 'updated':
779 case 'edited';
780 break;
781
782 case 'name':
783 $arEntry[$tag] = array();
784 foreach($child->children() as $subChild)
785 {
786 $arEntry[$tag][$subChild->name()] = $subChild->textContent();
787 }
788 break;
789
790 case 'email':
791
792 if($child->getAttribute('primary') == 'true')
793 {
794 $arEntry[$tag] = $child->getAttribute('address');
795 }
796
797 break;
798 default:
799
800 $tagContent = $tag == 'link'
801 ? $child->getAttribute('href')
802 : $child->textContent();
803
804 if($child->getAttribute('rel'))
805 {
806 if(!isset($arEntry[$tag]))
807 {
808 $arEntry[$tag] = array();
809 }
810
811 $arEntry[$tag][preg_replace("/^[^#]*#/", "", $child->getAttribute('rel'))] = $tagContent;
812 }
813 elseif(isset($arEntry[$tag]))
814 {
815 if(!is_array($arEntry[$tag][0]) || !isset($arEntry[$tag][0]))
816 {
817 $arEntry[$tag] = array($arEntry[$tag], $tagContent);
818 }
819 else
820 {
821 $arEntry[$tag][] = $tagContent;
822 }
823 }
824 else
825 {
826 $arEntry[$tag] = $tagContent;
827 }
828 }
829 }
830
831 if($arEntry['email'])
832 {
833 $arFriends[] = $arEntry;
834 }
835 }
836 return $arFriends;
837 }
838 }
839
840 return false;
841 }
842
843 public function getNewAccessToken($refreshToken = false, $userId = 0, $save = false)
844 {
845 if($this->appID == false || $this->appSecret == false)
846 {
847 return false;
848 }
849
850 if($refreshToken === false)
851 {
852 $refreshToken = $this->refresh_token;
853 }
854
855 $this->arResult = $this->getDecodedJson(static::TOKEN_URL, [
856 "client_id" => $this->appID,
857 "refresh_token"=>$refreshToken,
858 "grant_type"=>"refresh_token",
859 "client_secret" => $this->appSecret,
860 ]);
861
862 if (isset($this->arResult["access_token"]) && $this->arResult["access_token"] <> '')
863 {
864 $this->access_token = $this->arResult["access_token"];
865 $this->accessTokenExpires = $this->arResult["expires_in"] + time();
866 if ($save && intval($userId) > 0)
867 {
868 $dbSocservUser = \Bitrix\Socialservices\UserTable::getList(array(
869 'filter' => array(
870 '=EXTERNAL_AUTH_ID' => static::SERVICE_ID,
871 '=USER_ID' => $userId,
872 ),
873 'select' => array("ID")
874 ));
875 if($arOauth = $dbSocservUser->Fetch())
876 {
877 \Bitrix\Socialservices\UserTable::update($arOauth["ID"], array(
878 "OATOKEN" => $this->access_token,
879 "OATOKEN_EXPIRES" => $this->accessTokenExpires)
880 );
881 }
882 }
883
884 return true;
885 }
886
887 return false;
888 }
889
890 public function getRedirectUri()
891 {
892 return \CHTTP::URN2URI(static::REDIRECT_URI);
893 }
894}
$arParams
Определения access_dialog.php:21
$arResult
Определения generate_coupon.php:16
change_password_forgot_link login popup forget pas AUTH_GOTO_FORGOT_FORM login btn wrap change_password_button login popup link login popup return auth javascript
Определения change_password.php:57
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
static set($moduleId, $name, $value="", $siteId="")
Определения option.php:261
Определения jwk.php:18
Определения jwt.php:23
Определения json.php:9
GetAuthUrl($redirect_uri, $state='', $apiKey='')
Определения google.php:525
__construct($appID=false, $appSecret=false, $code=false)
Определения google.php:449
const CONTACTS_URL
Определения google.php:431
$arResult
Определения google.php:444
getNewAccessToken($refreshToken=false, $userId=0, $save=false)
Определения google.php:843
const TOKEN_URL
Определения google.php:430
getError()
Определения google.php:518
$scope
Определения google.php:442
string $idTokenAuth
Определения google.php:446
GetCurrentUser()
Определения google.php:667
const AUTH_URL
Определения google.php:429
const FRIENDS_URL
Определения google.php:432
getScopeEncode()
Определения google.php:508
addScope($scope)
Определения google.php:492
GetCurrentUserFriends($limit, &$next)
Определения google.php:720
setIdTokenAuth(string $tokenId)
Определения google.php:539
removeScope(string $scope)
Определения google.php:501
getRedirectUri()
Определения google.php:890
const REDIRECT_URI
Определения google.php:435
array $fetchedPublicKeys
Определения google.php:447
$standardScope
Определения google.php:437
GetAppInfo()
Определения google.php:691
checkSavedScope()
Определения google.php:473
getOptionNameForScopes()
Определения google.php:468
GetAccessToken($redirect_uri=false)
Определения google.php:593
saveScope()
Определения google.php:486
getResult()
Определения google.php:513
const JWT_ALG
Определения google.php:427
const TOKENINFO_URL
Определения google.php:433
Определения authmanager.php:985
Определения google.php:11
const ID
Определения google.php:12
CheckSettings()
Определения google.php:55
GetSettings()
Определения google.php:37
$entityOAuth
Определения google.php:16
getEntityOAuth($code=false)
Определения google.php:22
const LOGIN_PREFIX
Определения google.php:13
GetFormHtml($arParams)
Определения google.php:62
getStorageTokens()
Определения oauthtransport.php:116
deleteStorageTokens()
Определения oauthtransport.php:134
checkAccessToken()
Определения oauthtransport.php:153
getDecodedJson($url, $postData=null)
Определения oauthtransport.php:163
</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
$save
Определения iblock_catalog_edit.php:365
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
IsModuleInstalled($module_id)
Определения tools.php:5301
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
const SITE_ID
Определения sonet_set_content_view.php:12
path
Определения template_copy.php:201
$url
Определения iframe.php:7