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

Protected Member Functions

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

Protected Attributes

 $name = 'google_oauth'
 $title = 'Google'
 $type = 'OAuth'
 $jsArguments = array('popup' => array('width' => 500, 'height' => 450))
 $client_id = ''
 $client_secret = ''
 $scope = 'https://www.googleapis.com/auth/userinfo.profile'
 $providerOptions
- 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 GoogleOAuthService.php.

Member Function Documentation

GoogleOAuthService::fetchAttributes ( )
protected

Fetch attributes array.

Returns
boolean whether the attributes was successfully fetched.

Reimplemented from EAuthServiceBase.

Definition at line 33 of file GoogleOAuthService.php.

References EOAuth2Service\makeSignedRequest().

{
$info = (array)$this->makeSignedRequest('https://www.googleapis.com/oauth2/v1/userinfo');
$this->attributes['id'] = $info['id'];
$this->attributes['name'] = $info['name'];
if (!empty($info['link']))
$this->attributes['url'] = $info['link'];
/*if (!empty($info['gender']))
$this->attributes['gender'] = $info['gender'] == 'male' ? 'M' : 'F';
if (!empty($info['picture']))
$this->attributes['photo'] = $info['picture'];
$info['given_name']; // first name
$info['family_name']; // last name
$info['birthday']; // format: 0000-00-00
$info['locale']; // format: en*/
}
GoogleOAuthService::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 104 of file GoogleOAuthService.php.

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

References EAuthServiceBase\getState(), getTokenUrl(), and 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));
}
GoogleOAuthService::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 54 of file GoogleOAuthService.php.

References EAuthServiceBase\setState().

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

Returns the url to request to get OAuth2 access token.

Returns
string url to request.

Reimplemented from EOAuth2Service.

Definition at line 62 of file GoogleOAuthService.php.

Referenced by getAccessToken().

{
return $this->providerOptions['access_token'];
}
GoogleOAuthService::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 from EAuthServiceBase.

Definition at line 94 of file GoogleOAuthService.php.

Referenced by getAccessToken().

{
$options['query']['alt'] = 'json';
return parent::makeRequest($url, $options, $parseJson);
}
GoogleOAuthService::saveAccessToken (   $token)
protected

Save access token to the session.

Parameters
stdClass$tokenaccess token array.

Reimplemented from EOAuth2Service.

Definition at line 81 of file GoogleOAuthService.php.

References EAuthServiceBase\setState().

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

Member Data Documentation

GoogleOAuthService::$providerOptions
protected
Initial value:
array(
'authorize' => 'https://accounts.google.com/o/oauth2/auth',
'access_token' => 'https://accounts.google.com/o/oauth2/token',
)

Definition at line 28 of file GoogleOAuthService.php.


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