Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
MailruOAuthService Class Reference
Inheritance diagram for MailruOAuthService:
EOAuth2Service EAuthServiceBase IAuthService IAuthService CustomMailruService

Public Member Functions

 makeSignedRequest ($url, $options=array(), $parseJson=true)
- Public Member Functions inherited from EOAuth2Service
 authenticate ()
- Public Member Functions inherited from EAuthServiceBase
 __get ($name)
 __isset ($name)
 init ($component, $options=array())
 getServiceName ()
 getServiceTitle ()
 getServiceType ()
 getJsArguments ()
 setComponent ($component)
 getComponent ()
 setRedirectUrl ($url)
 getRedirectUrl ()
 setCancelUrl ($url)
 getCancelUrl ()
 getIsAuthenticated ()
 redirect ($url=null)
 cancel ($url=null)
 getId ()
 getAttributes ()
 getAttribute ($key, $default=null)
 hasAttribute ($key)
 getItem ()
 getItemAttributes ()
- Public Member Functions inherited from IAuthService
 cancel ()

Protected Member Functions

 fetchAttributes ()
 getCodeUrl ($redirect_uri)
 getTokenUrl ($code)
 getAccessToken ($code)
 saveAccessToken ($token)
 restoreAccessToken ()
 fetchJsonError ($json)

Protected Attributes

 $name = 'mailru'
 $title = 'Mail.ru'
 $type = 'OAuth'
 $jsArguments = array('popup' => array('width' => 580, 'height' => 400))
 $client_id = ''
 $client_secret = ''
 $scope = ''
 $providerOptions
 $uid = null
- Protected Attributes inherited from EOAuth2Service
 $client_id
 $client_secret
 $scope = ''
 $providerOptions
 $access_token = ''
- Protected Attributes inherited from EAuthServiceBase
 $name
 $title
 $type
 $jsArguments = array()
 $attributes = array()
 $authenticated = false

Detailed Description

Definition at line 18 of file MailruOAuthService.php.

Member Function Documentation

MailruOAuthService::fetchAttributes ( )
protected

Fetch attributes array.

Returns
boolean whether the attributes was successfully fetched.

Reimplemented from EAuthServiceBase.

Reimplemented in CustomMailruService.

Definition at line 35 of file MailruOAuthService.php.

References makeSignedRequest().

{
$info = (array)$this->makeSignedRequest('http://www.appsmail.ru/platform/api', array(
'query' => array(
'uids' => $this->uid,
'method' => 'users.getInfo',
'app_id' => $this->client_id,
),
));
$info = $info[0];
$this->attributes['id'] = $info->uid;
$this->attributes['name'] = $info->first_name.' '.$info->last_name;
$this->attributes['url'] = $info->link;
}
MailruOAuthService::fetchJsonError (   $json)
protected

Returns the error info from json.

Parameters
stdClass$jsonthe json response.
Returns
array the error array with 2 keys: code and message. Should be null if no errors.

Reimplemented from EAuthServiceBase.

Definition at line 124 of file MailruOAuthService.php.

{
if (isset($json->error)) {
return array(
'code' => $json->error_code,
'message' => $json->error_description,
);
}
else
return null;
}
MailruOAuthService::getAccessToken (   $code)
protected

Returns the OAuth2 access token.

Parameters
string$codethe OAuth2 code. See getCodeUrl.
Returns
string the token.

Reimplemented from EOAuth2Service.

Definition at line 65 of file MailruOAuthService.php.

References EAuthServiceBase\getState(), getTokenUrl(), and EAuthServiceBase\makeRequest().

{
$params = array(
'client_id' => $this->client_id,
'client_secret' => $this->client_secret,
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => $this->getState('redirect_uri'),
);
return $this->makeRequest($this->getTokenUrl($code), array('data' => $params));
}
MailruOAuthService::getCodeUrl (   $redirect_uri)
protected

Returns the url to request to get OAuth2 code.

Parameters
string$redirect_uriurl to redirect after user confirmation.
Returns
string url to request.

Reimplemented from EOAuth2Service.

Definition at line 51 of file MailruOAuthService.php.

References EAuthServiceBase\setState().

{
$this->setState('redirect_uri', $redirect_uri);
$url = parent::getCodeUrl($redirect_uri);
if (isset($_GET['js']))
$url .= '&display=popup';
return $url;
}
MailruOAuthService::getTokenUrl (   $code)
protected

Returns the url to request to get OAuth2 access token.

Returns
string url to request.

Reimplemented from EOAuth2Service.

Definition at line 61 of file MailruOAuthService.php.

Referenced by getAccessToken().

{
return $this->providerOptions['access_token'];
}
MailruOAuthService::makeSignedRequest (   $url,
  $options = array(),
  $parseJson = true 
)

Returns the protected resource.

Parameters
string$urlurl to request.
array$optionsHTTP request options. Keys: query, data, referer.
boolean$parseJsonWhether to parse response in json format.
Returns
string the response.
See Also
makeRequest

Reimplemented from EOAuth2Service.

Definition at line 103 of file MailruOAuthService.php.

References EAuthServiceBase\getIsAuthenticated(), and EAuthServiceBase\makeRequest().

Referenced by CustomMailruService\fetchAttributes(), and fetchAttributes().

{
if (!$this->getIsAuthenticated())
throw new CHttpException(401, Yii::t('eauth', 'Unable to complete the authentication because the required data was not received.', array('{provider}' => ucfirst($this->serviceName))));
$options['query']['secure'] = 1;
$options['query']['session_key'] = $this->access_token;
$_params = '';
ksort($options['query']);
foreach ($options['query'] as $k => $v)
$_params .= $k . '=' . $v;
$options['query']['sig'] = md5($_params . $this->client_secret);
$result = $this->makeRequest($url, $options);
return $result;
}
MailruOAuthService::restoreAccessToken ( )
protected

Restore access token from the session.

Returns
boolean whether the access token was successfuly restored.

Reimplemented from EOAuth2Service.

Definition at line 92 of file MailruOAuthService.php.

References EAuthServiceBase\getState(), and EAuthServiceBase\hasState().

{
if ($this->hasState('uid') && parent::restoreAccessToken()) {
$this->uid = $this->getState('uid');
return true;
}
else {
$this->uid = null;
return false;
}
}
MailruOAuthService::saveAccessToken (   $token)
protected

Save access token to the session.

Parameters
stdClass$tokenaccess token object.

Reimplemented from EOAuth2Service.

Definition at line 80 of file MailruOAuthService.php.

References EAuthServiceBase\setState().

{
$this->setState('auth_token', $token->access_token);
$this->setState('uid', $token->x_mailru_vid);
$this->setState('expires', time() + $token->expires_in - 60);
$this->uid = $token->x_mailru_vid;
$this->access_token = $token->access_token;
}

Member Data Documentation

MailruOAuthService::$providerOptions
protected
Initial value:
array(
'authorize' => 'https://connect.mail.ru/oauth/authorize',
'access_token' => 'https://connect.mail.ru/oauth/token',
)

Definition at line 28 of file MailruOAuthService.php.


The documentation for this class was generated from the following file: