Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
liveid.php
1<?php
2
4
7
9{
10
11 protected function __construct()
12 {
13 $this->oauthEntity = new LiveIdInterface;
14
15 $this->oauthEntity->addScope(array(
16 'wl.emails',
17 'wl.imap',
18 'wl.offline_access',
19 ));
20 }
21
22 protected function check()
23 {
24 $provider = new \CSocServLiveIdOAuth;
25
26 return $provider->checkSettings();
27 }
28
29 protected function mapUserData(array $userData)
30 {
31 return array(
32 'email' => $userData['emails']['account'],
33 'first_name' => $userData['first_name'],
34 'last_name' => $userData['last_name'],
35 'full_name' => $userData['name'],
36 'image' => sprintf('https://apis.live.net/v5.0/%s/picture?type=small', $userData['id']),
37 'error' => $userData['error']['message'],
38 );
39 }
40
41 public static function getServiceName()
42 {
43 return 'liveid';
44 }
45
46 public function getControllerUrl()
47 {
48 return \CSocServLiveIdOAuth::CONTROLLER_URL;
49 }
50
51}
52
53if (Main\Loader::includeModule('socialservices'))
54{
55 class_exists('CSocServLiveIdOAuth');
56
57 class LiveIdInterface extends \CLiveIdOAuthInterface
58 {
59
60 public function setCode($code)
61 {
62 $this->code = $code;
63 }
64
65 public function setToken($access_token)
66 {
68 }
69
70 public function getStorageTokens()
71 {
72 return false;
73 }
74
75 public function getTokenData()
76 {
77 return array(
78 'access_token' => $this->access_token,
79 'refresh_token' => $this->refresh_token,
80 'expires_in' => time() + $this->accessTokenExpires,
81 );
82 }
83
84 public function getCurrentUser()
85 {
86 if (empty($this->access_token))
87 {
88 return false;
89 }
90
91 $httpClient = new \Bitrix\Main\Web\HttpClient();
92 $httpClient->setHeader('Authorization', 'Bearer ' . $this->access_token);
93
94 $result = $httpClient->get(static::CONTACTS_URL);
95
96 if (!empty($result))
97 {
98 try
99 {
100 $result = \Bitrix\Main\Web\Json::decode($result);
101 }
102 catch (\Exception $e)
103 {
104 $result = null;
105 }
106 }
107
108 if (is_array($result))
109 {
110 $result = array_merge(
111 $result,
112 $this->getTokenData()
113 );
114 }
115
116 return $result;
117 }
118
119 }
120}
mapUserData(array $userData)
Definition liveid.php:29