Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FB: utf-8 was added to HttpClient to get access_token #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,36 @@
),

'facebook' => array(
'scope' => array(
'info_fields' => array(
/*
'id',
'name',
'gender',
'last_name',
'first_name',
'email',
'locale',
'verified'
//'...'
*/
),
'oauth' => array(
'scope' => array(
/*
'user_about_me',
'user_activities',
'user_birthday',
'read_friendlists',
//'...'
*/
),
'auth_uri' => 'https://www.facebook.com/dialog/oauth',
'token_uri' => 'https://graph.facebook.com/oauth/access_token',
'info_uri' => 'https://graph.facebook.com/me',
'client_id' => 'your id',
'client_secret' => 'your secret',
'redirect_uri' => 'your callback url which links to your controller',
),
'auth_uri' => 'https://www.facebook.com/dialog/oauth',
'token_uri' => 'https://graph.facebook.com/oauth/access_token',
'info_uri' => 'https://graph.facebook.com/me',
'client_id' => 'your id',
'client_secret' => 'your secret',
'redirect_uri' => 'your callback url which links to your controller',
),
),

'github' => array(
Expand Down
76 changes: 75 additions & 1 deletion src/ReverseOAuth2/Client/Facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,37 @@ class Facebook extends AbstractOAuth2Client
{

protected $providerName = 'facebook';
/**
*
* @var array
*/
protected $fields;

/**
*
* @param array $fields
*/
public function setFields($fields)
{
if (!is_array($fields)) {
throw new Exception("Error fields not is an array.");
} elseif (!count($fields)) {
throw new Exception("fields do not exist.");
}

$this->fields = $fields;

}

public function getFields()
{
if (!$this->fields) {
$this->fields = array('id', 'name');
}

return $this->fields;

}

public function getUrl()
{
Expand Down Expand Up @@ -36,7 +67,9 @@ public function getToken(Request $request)
$client = $this->getHttpClient();

$client->setUri($this->options->getTokenUri());


$client->setHeaders(array('Accept-encoding' => 'utf-8'));

$client->setMethod(Request::METHOD_POST);

$client->setParameterPost(array(
Expand Down Expand Up @@ -92,5 +125,46 @@ public function getToken(Request $request)
}

}

public function getInfo()
{
if(is_object($this->session->info)) {

return $this->session->info;

} elseif(isset($this->session->token->access_token)) {

$client = $this->getHttpclient()
->resetParameters(true)
->setHeaders(array('Accept-encoding' => 'utf-8'))
->setMethod(Request::METHOD_GET)
->setUri($this->options->getInfoUri());

$client->setParameterGet(array(
'access_token' => $this->session->token->access_token,
'fields' => implode(',', array_unique($this->fields))
));

$retVal = $client->send()->getContent();

if(strlen(trim($retVal)) > 0) {

$this->session->info = \Zend\Json\Decoder::decode($retVal);
return $this->session->info;

} else {

$this->error = array('internal-error' => 'Get info return value is empty.');
return false;

}

} else {

$this->error = array('internal-error' => 'Session access token not found.');
return false;

}
}

}
3 changes: 2 additions & 1 deletion src/ReverseOAuth2/Client/FacebookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class FacebookFactory implements FactoryInterface
public function createService(ServiceLocatorInterface $serviceLocator) {
$me = new \ReverseOAuth2\Client\Facebook;
$cf = $serviceLocator->get('Config');
$me->setOptions(new \ReverseOAuth2\ClientOptions($cf['reverseoauth2']['facebook']));
$me->setOptions(new \ReverseOAuth2\ClientOptions($cf['reverseoauth2']['facebook']['oauth']));
$me->setFields($cf['reverseoauth2']['facebook']['info_fields']);
return $me;
}
}