YandexOAuth2Service.php
1.36 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
50
51
<?php
/**
* YandexOAuth2Service class file.
*
* Register application: https://oauth.yandex.ru/client/my
*
* @author Maxim Zemskov <nodge@yandex.ru>
* @link http://github.com/Nodge/yii2-eauth/
* @license http://www.opensource.org/licenses/bsd-license.php
*/
namespace common\components\nodge\eauth\src\services;
use OAuth\Common\Token\TokenInterface;
use nodge\eauth\oauth2\Service;
/**
* Yandex OAuth provider class.
*
* @package application.extensions.eauth.services
*/
class YandexOAuth2Service extends Service
{
protected $name = 'yandex_oauth';
protected $title = 'Yandex';
protected $type = 'OAuth2';
protected $jsArguments = ['popup' => ['width' => 500, 'height' => 450]];
protected $tokenDefaultLifetime = TokenInterface::EOL_NEVER_EXPIRES;
protected $scope = [];
protected $providerOptions = [
'authorize' => 'https://oauth.yandex.ru/authorize',
'access_token' => 'https://oauth.yandex.ru/token',
];
protected function fetchAttributes()
{
$info = $this->makeSignedRequest('https://login.yandex.ru/info');
$this->attributes['id'] = $info['id'];
$this->attributes['name'] = $info['real_name'];
//$this->attributes['login'] = $info['display_name'];
//$this->attributes['email'] = $info['emails'][0];
//$this->attributes['email'] = $info['default_email'];
$this->attributes['gender'] = ($info['sex'] == 'male') ? 'M' : 'F';
return true;
}
}