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

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)
- Protected Member Functions inherited from EOAuth2Service
 restoreAccessToken ()
- Protected Member Functions inherited from EAuthServiceBase
 makeRequest ($url, $options=array(), $parseJson=true)
 initRequest ($url, $options=array())
 parseJson ($response)
 fetchJsonError ($json)
 getStateKeyPrefix ()
 setState ($key, $value, $defaultValue=null)
 hasState ($key)
 getState ($key, $defaultValue=null)
 _fetchAttributes ()

Protected Attributes

 $name = 'moikrug'
 $title = 'Moikrug.ru'
 $type = 'OAuth'
 $jsArguments = array('popup' => array('width' => 500, 'height' => 450))
 $client_id = ''
 $client_secret = ''
 $scope = ''
 $providerOptions
 $fields = ''
- 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 MoikrugOAuthService.php.

Member Function Documentation

MoikrugOAuthService::fetchAttributes ( )
protected

Fetch attributes array.

Returns
boolean whether the attributes was successfully fetched.

Reimplemented from EAuthServiceBase.

Definition at line 34 of file MoikrugOAuthService.php.

References makeSignedRequest().

{
$info = (array)$this->makeSignedRequest('https://api.moikrug.ru/v1/my/');
$info = (array)$info[0];
$this->attributes['id'] = $info['id'];
$this->attributes['name'] = $info['name'];
$this->attributes['url'] = $info['link'];
//$this->attributes['photo'] = $info['avatar']['SnippetSquare'];
$this->attributes['gender'] = ($info['gender'] == 'male') ? 'M' : 'F';
}
MoikrugOAuthService::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 55 of file MoikrugOAuthService.php.

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

{
$params = array(
'grant_type' => 'authorization_code',
'code' => $code,
'client_id' => $this->client_id,
'client_secret' => $this->client_secret,
);
return $this->makeRequest($this->getTokenUrl($code), array('data' => $params));
}
MoikrugOAuthService::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 44 of file MoikrugOAuthService.php.

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

Returns the url to request to get OAuth2 access token.

Returns
string url to request.

Reimplemented from EOAuth2Service.

Definition at line 51 of file MoikrugOAuthService.php.

Referenced by getAccessToken().

{
return $this->providerOptions['access_token'];
}
MoikrugOAuthService::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 83 of file MoikrugOAuthService.php.

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

Referenced by fetchAttributes().

{
if (!$this->getIsAuthenticated())
throw new CHttpException(401, 'Unable to complete the authentication because the required data was not received.');
$options['query']['oauth_token'] = $this->access_token;
$result = $this->makeRequest($url, $options);
return $result;
}
MoikrugOAuthService::saveAccessToken (   $token)
protected

Save access token to the session.

Parameters
stdClass$tokenaccess token array.

Reimplemented from EOAuth2Service.

Definition at line 69 of file MoikrugOAuthService.php.

References EAuthServiceBase\setState().

{
$this->setState('auth_token', $token->access_token);
$this->setState('expires', time() + (isset($token->expires_in) ? $token->expires_in : 365*86400) - 60);
$this->access_token = $token->access_token;
}

Member Data Documentation

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

Definition at line 28 of file MoikrugOAuthService.php.


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