VKontakteOAuth2Service.php
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* An example of extending the provider class.
*
* @author Maxim Zemskov <nodge@yandex.ru>
* @link http://github.com/Nodge/yii2-eauth/
* @license http://www.opensource.org/licenses/bsd-license.php
*/
namespace nodge\eauth\services\extended;
class VKontakteOAuth2Service extends \nodge\eauth\services\VKontakteOAuth2Service
{
// protected $scope = 'friends';
protected function fetchAttributes()
{
$tokenData = $this->getAccessTokenData();
$info = $this->makeSignedRequest('users.get.json', [
'query' => [
'uids' => $tokenData['params']['user_id'],
'fields' => '', // uid, first_name and last_name is always available
'fields' => 'nickname, sex, bdate, city, country, timezone, photo, photo_medium, photo_big, photo_rec',
],
]);
$info = $info['response'][0];
$this->attributes = $info;
$this->attributes['id'] = $info['uid'];
$this->attributes['name'] = $info['first_name'] . ' ' . $info['last_name'];
$this->attributes['url'] = 'http://vk.com/id' . $info['uid'];
if (!empty($info['nickname'])) {
$this->attributes['username'] = $info['nickname'];
} else {
$this->attributes['username'] = 'id' . $info['uid'];
}
$this->attributes['gender'] = $info['sex'] == 1 ? 'F' : 'M';
if (!empty($info['timezone'])) {
$this->attributes['timezone'] = timezone_name_from_abbr('', $info['timezone'] * 3600, date('I'));
}
return true;
}
}