12 require_once dirname(dirname(__FILE__)) .
'/EOAuth2Service.php';
20 protected $name =
'mailru';
21 protected $title =
'Mail.ru';
22 protected $type =
'OAuth';
23 protected $jsArguments = array(
'popup' => array(
'width' => 580,
'height' => 400));
25 protected $client_id =
'';
26 protected $client_secret =
'';
27 protected $scope =
'';
28 protected $providerOptions = array(
29 'authorize' =>
'https://connect.mail.ru/oauth/authorize',
30 'access_token' =>
'https://connect.mail.ru/oauth/token',
33 protected $uid = null;
36 $info = (array)$this->
makeSignedRequest(
'http://www.appsmail.ru/platform/api', array(
39 'method' =>
'users.getInfo',
40 'app_id' => $this->client_id,
46 $this->attributes[
'id'] = $info->uid;
47 $this->attributes[
'name'] = $info->first_name.
' '.$info->last_name;
48 $this->attributes[
'url'] = $info->link;
52 $this->
setState(
'redirect_uri', $redirect_uri);
55 if (isset($_GET[
'js']))
56 $url .=
'&display=popup';
62 return $this->providerOptions[
'access_token'];
67 'client_id' => $this->client_id,
68 'client_secret' => $this->client_secret,
69 'grant_type' =>
'authorization_code',
71 'redirect_uri' => $this->
getState(
'redirect_uri'),
81 $this->
setState(
'auth_token', $token->access_token);
82 $this->
setState(
'uid', $token->x_mailru_vid);
83 $this->
setState(
'expires', time() + $token->expires_in - 60);
84 $this->uid = $token->x_mailru_vid;
85 $this->access_token = $token->access_token;
93 if ($this->
hasState(
'uid') && parent::restoreAccessToken()) {
105 throw new CHttpException(401, Yii::t(
'eauth',
'Unable to complete the authentication because the required data was not received.', array(
'{provider}' => ucfirst($this->serviceName))));
107 $options[
'query'][
'secure'] = 1;
108 $options[
'query'][
'session_key'] = $this->access_token;
110 ksort($options[
'query']);
111 foreach ($options[
'query'] as $k => $v)
112 $_params .= $k .
'=' . $v;
113 $options[
'query'][
'sig'] = md5($_params . $this->client_secret);
125 if (isset($json->error)) {
127 'code' => $json->error_code,
128 'message' => $json->error_description,