Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
EAuthServiceBase Class Reference
Inheritance diagram for EAuthServiceBase:
IAuthService EmailService EOAuth2Service EOAuthService EOpenIDService FacebookOAuthService GoogleOAuthService MailruOAuthService MoikrugOAuthService OdnoklassnikiOAuthService VKontakteOAuthService TwitterOAuthService GoogleOpenIDService YandexOpenIDService

Public Member Functions

 __get ($name)
 __isset ($name)
 init ($component, $options=array())
 getServiceName ()
 getServiceTitle ()
 getServiceType ()
 getJsArguments ()
 setComponent ($component)
 getComponent ()
 setRedirectUrl ($url)
 getRedirectUrl ()
 setCancelUrl ($url)
 getCancelUrl ()
 authenticate ()
 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

 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

 $name
 $title
 $type
 $jsArguments = array()
 $attributes = array()
 $authenticated = false

Detailed Description

Definition at line 16 of file EAuthServiceBase.php.

Member Function Documentation

EAuthServiceBase::__get (   $name)

PHP getter magic method. This method is overridden so that service attributes can be accessed like properties.

Parameters
string$nameproperty name.
Returns
mixed property value.
See Also
getAttribute

Definition at line 79 of file EAuthServiceBase.php.

References getAttribute(), and hasAttribute().

{
if ($this->hasAttribute($name))
return $this->getAttribute($name);
else
return parent::__get($name);
}
EAuthServiceBase::__isset (   $name)

Checks if a attribute value is null. This method overrides the parent implementation by checking if the attribute is null or not.

Parameters
string$namethe attribute name.
Returns
boolean whether the attribute value is null.

Definition at line 93 of file EAuthServiceBase.php.

References hasAttribute().

{
if ($this->hasAttribute($name))
return true;
else
return parent::__isset($name);
}
EAuthServiceBase::_fetchAttributes ( )
protected

Fetch attributes array. This function is internally used to handle fetched state.

Definition at line 408 of file EAuthServiceBase.php.

References fetchAttributes().

Referenced by getAttribute(), getAttributes(), getId(), and hasAttribute().

{
if (!$this->fetched) {
$this->fetched = true;
$result = $this->fetchAttributes();
if (isset($result))
$this->fetched = $result;
}
}
EAuthServiceBase::authenticate ( )

Authenticate the user.

Returns
boolean whether user was successfuly authenticated.

Implements IAuthService.

Reimplemented in EOAuthService, EmailService, EOAuth2Service, TwitterOAuthService, and EOpenIDService.

Definition at line 203 of file EAuthServiceBase.php.

References getIsAuthenticated().

{
return $this->getIsAuthenticated();
}
EAuthServiceBase::cancel (   $url = null)

Redirect to the cancelUrl or simply close the popup window.

Reimplemented in EmailService.

Definition at line 226 of file EAuthServiceBase.php.

{
$this->component->redirect(isset($url) ? $url : $this->cancelUrl, false);
}
EAuthServiceBase::fetchAttributes ( )
protected
EAuthServiceBase::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 in MailruOAuthService, VKontakteOAuthService, GoogleOAuthService, FacebookOAuthService, and OdnoklassnikiOAuthService.

Definition at line 336 of file EAuthServiceBase.php.

Referenced by parseJson().

{
if (isset($json->error)) {
return array(
'code' => 500,
'message' => 'Unknown error occurred.',
);
}
else
return null;
}
EAuthServiceBase::getAttribute (   $key,
  $default = null 
)

Returns the authorization attribute value.

Parameters
string$keythe attribute name.
mixed$defaultthe default value.
Returns
mixed the attribute value.

Implements IAuthService.

Definition at line 445 of file EAuthServiceBase.php.

References _fetchAttributes().

Referenced by __get(), getAttributes(), and getItem().

{
$this->_fetchAttributes();
$getter = 'get'.$key;
if (method_exists($this, $getter))
return $this->$getter();
else
return isset($this->attributes[$key]) ? $this->attributes[$key] : $default;
}
EAuthServiceBase::getAttributes ( )

Returns the array that contains all available authorization attributes.

Returns
array the attributes.

Implements IAuthService.

Definition at line 430 of file EAuthServiceBase.php.

References _fetchAttributes(), and getAttribute().

Referenced by getItemAttributes().

{
$this->_fetchAttributes();
$attributes = array();
foreach ($this->attributes as $key => $val) {
$attributes[$key] = $this->getAttribute($key);
}
return $attributes;
}
EAuthServiceBase::getCancelUrl ( )

Returns the redirect url after unsuccessful authorization (e.g. user canceled).

Returns
string the redirect url after unsuccessful authorization (e.g. user canceled).

Implements IAuthService.

Definition at line 195 of file EAuthServiceBase.php.

Referenced by EmailService\cancel().

{
return $this->cancelUrl;
}
EAuthServiceBase::getComponent ( )

Returns the EAuth application component.

Returns
EAuth the EAuth application component.

Implements IAuthService.

Definition at line 163 of file EAuthServiceBase.php.

{
return $this->component;
}
EAuthServiceBase::getId ( )

Returns the user unique id.

Returns
mixed the user id.

Implements IAuthService.

Definition at line 421 of file EAuthServiceBase.php.

References _fetchAttributes().

Referenced by getItem().

{
$this->_fetchAttributes();
return $this->attributes['id'];
}
EAuthServiceBase::getIsAuthenticated ( )

Whether user was successfuly authenticated.

Returns
boolean whether user was successfuly authenticated.

Implements IAuthService.

Definition at line 211 of file EAuthServiceBase.php.

Referenced by EOAuth2Service\authenticate(), EOAuthService\authenticate(), authenticate(), MoikrugOAuthService\makeSignedRequest(), MailruOAuthService\makeSignedRequest(), EOAuthService\makeSignedRequest(), and EOAuth2Service\makeSignedRequest().

{
return $this->authenticated;
}
EAuthServiceBase::getItem ( )

Returns the object with a human-readable representation of the current authorization.

Returns
stdClass the object.

Implements IAuthService.

Definition at line 468 of file EAuthServiceBase.php.

References getAttribute(), getId(), and hasAttribute().

{
$item = new stdClass;
$item->title = $this->getAttribute('name');
if (empty($this->title))
$item->title = $this->getId();
if ($this->hasAttribute('url'))
$item->url = $this->getAttribute('url');
return $item;
}
EAuthServiceBase::getItemAttributes ( )

Returns the array that contains all available authorization attributes.

Returns
array the attributes.
Deprecated:
because getAttributes is more semantic.

Definition at line 483 of file EAuthServiceBase.php.

References getAttributes().

{
return $this->getAttributes();
}
EAuthServiceBase::getJsArguments ( )

Returns arguments for the jQuery.eauth() javascript function.

Returns
array the arguments for the jQuery.eauth() javascript function.

Implements IAuthService.

Definition at line 147 of file EAuthServiceBase.php.

{
return $this->jsArguments;
}
EAuthServiceBase::getRedirectUrl ( )

Returns the redirect url after successful authorization.

Returns
string the redirect url after successful authorization.

Implements IAuthService.

Definition at line 179 of file EAuthServiceBase.php.

Referenced by EmailService\redirect().

{
return $this->redirectUrl;
}
EAuthServiceBase::getServiceName ( )

Returns service name(id).

Returns
string the service name(id).

Implements IAuthService.

Definition at line 123 of file EAuthServiceBase.php.

Referenced by EOpenIDService\authenticate().

{
return $this->name;
}
EAuthServiceBase::getServiceTitle ( )

Returns service title.

Returns
string the service title.

Implements IAuthService.

Definition at line 131 of file EAuthServiceBase.php.

{
return $this->title;
}
EAuthServiceBase::getServiceType ( )

Returns service type (e.g. OpenID, OAuth).

Returns
string the service type (e.g. OpenID, OAuth).

Implements IAuthService.

Definition at line 139 of file EAuthServiceBase.php.

{
return $this->type;
}
EAuthServiceBase::getState (   $key,
  $defaultValue = null 
)
protected

Returns the value of a variable that is stored in eauth session.

Parameters
string$keyvariable name.
mixed$defaultValuedefault value.
Returns
mixed the value of the variable. If it doesn't exist in the session, the provided default value will be returned.
See Also
setState

Definition at line 390 of file EAuthServiceBase.php.

References getStateKeyPrefix().

Referenced by OdnoklassnikiOAuthService\getAccessToken(), MailruOAuthService\getAccessToken(), GoogleOAuthService\getAccessToken(), FacebookOAuthService\getTokenUrl(), MailruOAuthService\restoreAccessToken(), VKontakteOAuthService\restoreAccessToken(), and EOAuth2Service\restoreAccessToken().

{
$session = Yii::app()->session;
$key = $this->getStateKeyPrefix().$key;
return isset($session[$key]) ? $session[$key] : $defaultValue;
}
EAuthServiceBase::getStateKeyPrefix ( )
protected
Returns
string a prefix for the name of the session variables storing eauth session data.

Definition at line 350 of file EAuthServiceBase.php.

Referenced by getState(), hasState(), and setState().

{
return '__eauth_'.$this->getServiceName().'__';
}
EAuthServiceBase::hasAttribute (   $key)

Whether the authorization attribute exists.

Parameters
string$keythe attribute name.
Returns
boolean true if attribute exists, false otherwise.

Implements IAuthService.

Definition at line 459 of file EAuthServiceBase.php.

References _fetchAttributes().

Referenced by __get(), __isset(), and getItem().

{
$this->_fetchAttributes();
return isset($this->attributes[$key]);
}
EAuthServiceBase::hasState (   $key)
protected

Returns a value indicating whether there is a state of the specified name.

Parameters
string$keystate name.
Returns
boolean whether there is a state of the specified name.

Definition at line 376 of file EAuthServiceBase.php.

References getStateKeyPrefix().

Referenced by MailruOAuthService\restoreAccessToken(), VKontakteOAuthService\restoreAccessToken(), and EOAuth2Service\restoreAccessToken().

{
$session = Yii::app()->session;
$key = $this->getStateKeyPrefix().$key;
return isset($session[$key]);
}
EAuthServiceBase::init (   $component,
  $options = array() 
)

Initialize the component. Sets the default redirectUrl and cancelUrl.

Parameters
EAuth$componentthe component instance.
array$optionsproperties initialization.

Implements IAuthService.

Reimplemented in EOAuthService, and EOpenIDService.

Definition at line 106 of file EAuthServiceBase.php.

References setCancelUrl(), setComponent(), and setRedirectUrl().

{
if (isset($component))
$this->setComponent($component);
foreach ($options as $key => $val)
$this->$key = $val;
$this->setRedirectUrl(Yii::app()->user->returnUrl);
$server = Yii::app()->request->getHostInfo();
$path = Yii::app()->request->getPathInfo();
$this->setCancelUrl($server.'/'.$path);
}
EAuthServiceBase::initRequest (   $url,
  $options = array() 
)
protected

Initializes a new session and return a cURL handle.

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

Reimplemented in EOAuthService.

Definition at line 297 of file EAuthServiceBase.php.

Referenced by makeRequest().

{
$ch = curl_init();
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // error with open_basedir or safe mode
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
return $ch;
}
EAuthServiceBase::makeRequest (   $url,
  $options = array(),
  $parseJson = true 
)
protected

Makes the curl request to the url.

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.

Reimplemented in GoogleOAuthService.

Definition at line 237 of file EAuthServiceBase.php.

References initRequest(), and parseJson().

Referenced by OdnoklassnikiOAuthService\fetchAttributes(), MoikrugOAuthService\getAccessToken(), OdnoklassnikiOAuthService\getAccessToken(), FacebookOAuthService\getAccessToken(), MailruOAuthService\getAccessToken(), EOAuth2Service\getAccessToken(), CustomOdnoklassnikiService\getRealIdAndUrl(), MoikrugOAuthService\makeSignedRequest(), MailruOAuthService\makeSignedRequest(), EOAuthService\makeSignedRequest(), and EOAuth2Service\makeSignedRequest().

{
$ch = $this->initRequest($url, $options);
if (isset($options['referer']))
curl_setopt($ch, CURLOPT_REFERER, $options['referer']);
if (isset($options['query'])) {
$url_parts = parse_url($url);
if (isset($url_parts['query'])) {
$old_query = http_build_query($url_parts['query']);
$url_parts['query'] = array_merge($url_parts['query'], $options['query']);
$new_query = http_build_query($url_parts['query']);
$url = str_replace($old_query, $new_query, $url);
}
else {
$url_parts['query'] = $options['query'];
$new_query = http_build_query($url_parts['query']);
$url .= '?'.$new_query;
}
}
if (isset($options['data'])) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $options['data']);
}
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
if (curl_errno($ch) > 0)
throw new EAuthException(curl_error($ch), curl_errno($ch));
if ($headers['http_code'] != 200) {
Yii::log(
'Invalid response http code: '.$headers['http_code'].'.'.PHP_EOL.
'URL: '.$url.PHP_EOL.
'Options: '.var_export($options, true).PHP_EOL.
'Result: '.$result,
CLogger::LEVEL_ERROR, 'application.extensions.eauth'
);
throw new EAuthException(Yii::t('eauth', 'Invalid response http code: {code}.', array('{code}' => $headers['http_code'])), $headers['http_code']);
}
curl_close($ch);
if ($parseJson)
$result = $this->parseJson($result);
return $result;
}
EAuthServiceBase::parseJson (   $response)
protected

Parse response from makeRequest in json format and check OAuth errors.

Parameters
string$responseJson string.
Returns
object result.

Definition at line 313 of file EAuthServiceBase.php.

References fetchJsonError().

Referenced by makeRequest().

{
try {
$result = json_decode($response);
$error = $this->fetchJsonError($result);
if (!isset($result)) {
throw new EAuthException(Yii::t('eauth', 'Invalid response format.', array()), 500);
}
else if (isset($error)) {
throw new EAuthException($error['message'], $error['code']);
}
else
return $result;
}
catch(Exception $e) {
throw new EAuthException($e->getMessage(), $e->getCode());
}
}
EAuthServiceBase::redirect (   $url = null)

Redirect to the url. If url is null, redirectUrl will be used.

Parameters
string$urlurl to redirect.

Implements IAuthService.

Reimplemented in EmailService.

Definition at line 219 of file EAuthServiceBase.php.

{
$this->component->redirect(isset($url) ? $url : $this->redirectUrl, true);
}
EAuthServiceBase::setCancelUrl (   $url)

Sets redirect url after unsuccessful authorization (e.g. user canceled).

Parameters
stringurl to redirect.

Implements IAuthService.

Definition at line 187 of file EAuthServiceBase.php.

Referenced by init().

{
$this->cancelUrl = $url;
}
EAuthServiceBase::setComponent (   $component)

Sets EAuth application component

Parameters
EAuth$componentthe application auth component.

Implements IAuthService.

Definition at line 155 of file EAuthServiceBase.php.

Referenced by init().

{
$this->component = $component;
}
EAuthServiceBase::setRedirectUrl (   $url)

Sets redirect url after successful authorization.

Parameters
stringurl to redirect.

Implements IAuthService.

Definition at line 171 of file EAuthServiceBase.php.

Referenced by init().

{
$this->redirectUrl = $url;
}
EAuthServiceBase::setState (   $key,
  $value,
  $defaultValue = null 
)
protected

Stores a variable in eauth session.

Parameters
string$keyvariable name.
mixed$valuevariable value.
mixed$defaultValuedefault value. If $value===$defaultValue, the variable will be removed from the session.
See Also
getState

Definition at line 362 of file EAuthServiceBase.php.

References getStateKeyPrefix().

Referenced by FacebookOAuthService\getCodeUrl(), MailruOAuthService\getCodeUrl(), GoogleOAuthService\getCodeUrl(), OdnoklassnikiOAuthService\getCodeUrl(), MoikrugOAuthService\saveAccessToken(), FacebookOAuthService\saveAccessToken(), MailruOAuthService\saveAccessToken(), GoogleOAuthService\saveAccessToken(), VKontakteOAuthService\saveAccessToken(), and EOAuth2Service\saveAccessToken().

{
$session = Yii::app()->session;
$key = $this->getStateKeyPrefix().$key;
if($value === $defaultValue)
unset($session[$key]);
else
$session[$key] = $value;
}

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