Skip to content

Commit

Permalink
Implement Facebook\Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Sep 15, 2014
1 parent 4e8429d commit 10cacfb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"psr-4": {
"SocialConnect\\Auth\\": "src/",
"SocialConnect\\Vk\\": "providers/Vk/",
"SocialConnect\\Github\\": "providers/Github/"
"SocialConnect\\Github\\": "providers/Github/",
"SocialConnect\\Facebook\\": "providers/Facebook/"
}
}
}
60 changes: 60 additions & 0 deletions providers/Facebook/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* SocialConnect project
* @author: Patsura Dmitry https://github.com/ovr <talk@dmtry.me>
*/

namespace SocialConnect\Facebook;

use SocialConnect\Auth\Provider\OAuth2\AccessToken;
use SocialConnect\Common\Entity\User;
use SocialConnect\Common\Hydrator\ObjectMap;

class Provider extends \SocialConnect\Auth\Provider\OAuth2\Provider
{
public function getBaseUri()
{
return 'https://graph.facebook.com/';
}

public function getAuthorizeUri()
{
return 'https://www.facebook.com/dialog/oauth';
}

public function getRequestTokenUri()
{
return 'https://graph.facebook.com/oauth/access_token';
}

public function getName()
{
return 'facebook';
}

/**
* @param AccessToken $accessToken
* @return User
*/
public function getUser(AccessToken $accessToken)
{
$response = $this->service->getHttpClient()->request($this->getBaseUri() . '/me?access_token=' . $accessToken->getToken());
$body = $response->getBody();
$result = json_decode($body);

$hydrator = new ObjectMap(array(
'id' => 'id',
'first_name' => 'firstname',
'last_name' => 'lastname',
'gender' => 'sex',
'link' => 'url',
'locale' => 'locale',
'name' => 'username',
'timezone' => 'timezone',
'updated_time' => 'dateModified',
'verified' => 'verified'
));

return $hydrator->hydrate(new User(), $result);
}
}

0 comments on commit 10cacfb

Please sign in to comment.