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

Protected Member Functions

 fetchAttributes ()
 getCodeUrl ($redirect_uri)
 saveAccessToken ($token)
 restoreAccessToken ()
 fetchJsonError ($json)
- Protected Member Functions inherited from EOAuth2Service
 getTokenUrl ($code)
 getAccessToken ($code)
- Protected Member Functions inherited from EAuthServiceBase
 makeRequest ($url, $options=array(), $parseJson=true)
 initRequest ($url, $options=array())
 parseJson ($response)
 getStateKeyPrefix ()
 setState ($key, $value, $defaultValue=null)
 hasState ($key)
 getState ($key, $defaultValue=null)
 _fetchAttributes ()

Protected Attributes

 $name = 'vkontakte'
 $title = 'VK.com'
 $type = 'OAuth'
 $jsArguments = array('popup' => array('width' => 585, 'height' => 350))
 $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

Additional Inherited Members

- Public Member Functions inherited from EOAuth2Service
 authenticate ()
 makeSignedRequest ($url, $options=array(), $parseJson=true)

Detailed Description

Definition at line 18 of file VKontakteOAuthService.php.

Member Function Documentation

VKontakteOAuthService::fetchAttributes ( )
protected

Fetch attributes array.

Returns
boolean whether the attributes was successfully fetched.

Reimplemented from EAuthServiceBase.

Reimplemented in CustomVKontakteService.

Definition at line 35 of file VKontakteOAuthService.php.

References EOAuth2Service\makeSignedRequest().

{
$info = (array)$this->makeSignedRequest('https://api.vkontakte.ru/method/getProfiles', array(
'query' => array(
'uids' => $this->uid,
'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['id'] = $info->uid;
$this->attributes['name'] = $info->first_name.' '.$info->last_name;
$this->attributes['url'] = 'http://vkontakte.ru/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';
$this->attributes['city'] = $info->city;
$this->attributes['country'] = $info->country;
$this->attributes['timezone'] = timezone_name_from_abbr('', $info->timezone*3600, date('I'));;
$this->attributes['photo'] = $info->photo;
$this->attributes['photo_medium'] = $info->photo_medium;
$this->attributes['photo_big'] = $info->photo_big;
$this->attributes['photo_rec'] = $info->photo_rec;*/
}
VKontakteOAuthService::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 112 of file VKontakteOAuthService.php.

{
if (isset($json->error)) {
return array(
'code' => $json->error->error_code,
'message' => $json->error->error_msg,
);
}
else
return null;
}
VKontakteOAuthService::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 73 of file VKontakteOAuthService.php.

{
$url = parent::getCodeUrl($redirect_uri);
if (isset($_GET['js']))
$url .= '&display=popup';
return $url;
}
VKontakteOAuthService::restoreAccessToken ( )
protected

Restore access token from the session.

Returns
boolean whether the access token was successfuly restored.

Reimplemented from EOAuth2Service.

Definition at line 96 of file VKontakteOAuthService.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;
}
}
VKontakteOAuthService::saveAccessToken (   $token)
protected

Save access token to the session.

Parameters
stdClass$tokenaccess token object.

Reimplemented from EOAuth2Service.

Definition at line 84 of file VKontakteOAuthService.php.

References EAuthServiceBase\setState().

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

Member Data Documentation

VKontakteOAuthService::$providerOptions
protected
Initial value:
array(
'authorize' => 'http://api.vkontakte.ru/oauth/authorize',
'access_token' => 'https://api.vkontakte.ru/oauth/access_token',
)

Definition at line 28 of file VKontakteOAuthService.php.


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