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

Public Member Functions

 authenticate ()
 makeSignedRequest ($url, $options=array(), $parseJson=true)
- 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

 getCodeUrl ($redirect_uri)
 getTokenUrl ($code)
 getAccessToken ($code)
 saveAccessToken ($token)
 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 ()
 _fetchAttributes ()

Protected Attributes

 $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 16 of file EOAuth2Service.php.

Member Function Documentation

EOAuth2Service::authenticate ( )

Authenticate the user.

Returns
boolean whether user was successfuly authenticated.

Reimplemented from EAuthServiceBase.

Definition at line 51 of file EOAuth2Service.php.

References IAuthService\cancel(), getAccessToken(), getCodeUrl(), EAuthServiceBase\getIsAuthenticated(), restoreAccessToken(), and saveAccessToken().

{
// user denied error
if (isset($_GET['error']) && $_GET['error'] == 'access_denied') {
$this->cancel();
return false;
}
// Get the access_token and save them to the session.
if (isset($_GET['code'])) {
$code = $_GET['code'];
$token = $this->getAccessToken($code);
if (isset($token)) {
$this->saveAccessToken($token);
$this->authenticated = true;
}
}
// Redirect to the authorization page
else if (!$this->restoreAccessToken()) {
// Use the URL of the current page as the callback URL.
if (isset($_GET['redirect_uri'])) {
$redirect_uri = $_GET['redirect_uri'];
}
else {
$server = Yii::app()->request->getHostInfo();
$path = Yii::app()->request->getUrl();
$redirect_uri = $server.$path;
}
$url = $this->getCodeUrl($redirect_uri);
Yii::app()->request->redirect($url);
}
return $this->getIsAuthenticated();
}
EOAuth2Service::getAccessToken (   $code)
protected

Returns the OAuth2 access token.

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

Reimplemented in GoogleOAuthService, MailruOAuthService, FacebookOAuthService, OdnoklassnikiOAuthService, and MoikrugOAuthService.

Definition at line 107 of file EOAuth2Service.php.

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

Referenced by authenticate().

{
return $this->makeRequest($this->getTokenUrl($code));
}
EOAuth2Service::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 in VKontakteOAuthService, OdnoklassnikiOAuthService, GoogleOAuthService, MailruOAuthService, MoikrugOAuthService, and FacebookOAuthService.

Definition at line 90 of file EOAuth2Service.php.

Referenced by authenticate().

{
return $this->providerOptions['authorize'].'?client_id='.$this->client_id.'&redirect_uri='.urlencode($redirect_uri).'&scope='.$this->scope.'&response_type=code';
}
EOAuth2Service::getTokenUrl (   $code)
protected

Returns the url to request to get OAuth2 access token.

Returns
string url to request.

Reimplemented in GoogleOAuthService, MailruOAuthService, FacebookOAuthService, OdnoklassnikiOAuthService, and MoikrugOAuthService.

Definition at line 98 of file EOAuth2Service.php.

Referenced by getAccessToken().

{
return $this->providerOptions['access_token'].'?client_id='.$this->client_id.'&client_secret='.$this->client_secret.'&code='.$code;
}
EOAuth2Service::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 in MailruOAuthService, and MoikrugOAuthService.

Definition at line 145 of file EOAuth2Service.php.

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

Referenced by CustomVKontakteService\fetchAttributes(), FacebookService\fetchAttributes(), FacebookOAuthService\fetchAttributes(), GoogleOAuthService\fetchAttributes(), and VKontakteOAuthService\fetchAttributes().

{
if (!$this->getIsAuthenticated())
throw new CHttpException(401, Yii::t('eauth', 'Unable to complete the request because the user was not authenticated.'));
$options['query']['access_token'] = $this->access_token;
$result = $this->makeRequest($url, $options);
return $result;
}
EOAuth2Service::restoreAccessToken ( )
protected

Restore access token from the session.

Returns
boolean whether the access token was successfuly restored.

Reimplemented in VKontakteOAuthService, and MailruOAuthService.

Definition at line 124 of file EOAuth2Service.php.

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

Referenced by authenticate().

{
if ($this->hasState('auth_token') && $this->getState('expires', 0) > time()) {
$this->access_token = $this->getState('auth_token');
$this->authenticated = true;
return true;
}
else {
$this->access_token = null;
$this->authenticated = false;
return false;
}
}
EOAuth2Service::saveAccessToken (   $token)
protected

Save access token to the session.

Parameters
string$tokenaccess token.

Reimplemented in VKontakteOAuthService, GoogleOAuthService, MailruOAuthService, FacebookOAuthService, and MoikrugOAuthService.

Definition at line 115 of file EOAuth2Service.php.

References EAuthServiceBase\setState().

Referenced by authenticate().

{
$this->setState('auth_token', $token);
$this->access_token = $token;
}

Member Data Documentation

EOAuth2Service::$providerOptions
protected
Initial value:
array(
'authorize' => '',
'access_token' => '',
)

Definition at line 36 of file EOAuth2Service.php.


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