2013-01-29 20:06:24 +04:00
|
|
|
<?php
|
2013-05-28 14:00:24 +04:00
|
|
|
|
|
|
|
namespace League\OAuth2\Client\Provider;
|
2013-01-29 20:06:24 +04:00
|
|
|
|
2014-04-28 22:00:26 +04:00
|
|
|
use League\OAuth2\Client\Entity\User;
|
|
|
|
|
2014-04-28 19:44:39 +04:00
|
|
|
class Facebook extends AbstractProvider
|
2013-01-29 20:06:24 +04:00
|
|
|
{
|
2014-11-09 00:30:40 +03:00
|
|
|
public $scopes = ['offline_access', 'email', 'read_stream'];
|
2013-03-15 14:53:55 +04:00
|
|
|
public $responseType = 'string';
|
2013-01-29 20:06:24 +04:00
|
|
|
|
2013-01-29 20:08:47 +04:00
|
|
|
public function urlAuthorize()
|
|
|
|
{
|
|
|
|
return 'https://www.facebook.com/dialog/oauth';
|
|
|
|
}
|
2013-01-29 20:06:24 +04:00
|
|
|
|
2013-01-29 20:08:47 +04:00
|
|
|
public function urlAccessToken()
|
|
|
|
{
|
|
|
|
return 'https://graph.facebook.com/oauth/access_token';
|
|
|
|
}
|
2013-01-29 20:06:24 +04:00
|
|
|
|
2013-08-18 15:21:48 +04:00
|
|
|
public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token)
|
2013-01-29 20:08:47 +04:00
|
|
|
{
|
2013-02-26 16:02:52 +04:00
|
|
|
return 'https://graph.facebook.com/me?access_token='.$token;
|
|
|
|
}
|
2013-01-29 20:06:24 +04:00
|
|
|
|
2013-08-18 15:21:48 +04:00
|
|
|
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
|
2013-02-26 16:02:52 +04:00
|
|
|
{
|
2014-04-24 22:36:42 +04:00
|
|
|
$client = $this->getHttpClient();
|
2014-11-09 00:30:40 +03:00
|
|
|
$client->setBaseUrl('https://graph.facebook.com/me/picture?type=normal&access_token='.$token->accessToken);
|
2014-04-24 22:36:42 +04:00
|
|
|
$request = $client->get()->send();
|
|
|
|
$info = $request->getInfo();
|
|
|
|
$imageUrl = $info['url'];
|
2013-03-15 14:54:11 +04:00
|
|
|
|
2014-11-09 00:30:40 +03:00
|
|
|
$user = new User();
|
2014-04-28 22:00:26 +04:00
|
|
|
|
|
|
|
$username = (isset($response->username)) ? $response->username : null;
|
|
|
|
$email = (isset($response->email)) ? $response->email : null;
|
|
|
|
$location = (isset($response->hometown->name)) ? $response->hometown->name : null;
|
|
|
|
$description = (isset($response->bio)) ? $response->bio : null;
|
|
|
|
$imageUrl = ($imageUrl) ?: null;
|
|
|
|
|
2014-11-09 00:30:40 +03:00
|
|
|
$user->exchangeArray([
|
2014-04-28 22:00:26 +04:00
|
|
|
'uid' => $response->id,
|
|
|
|
'nickname' => $username,
|
|
|
|
'name' => $response->name,
|
|
|
|
'firstname' => $response->first_name,
|
|
|
|
'lastname' => $response->last_name,
|
|
|
|
'email' => $email,
|
|
|
|
'location' => $location,
|
|
|
|
'description' => $description,
|
|
|
|
'imageurl' => $imageUrl,
|
2014-11-09 00:30:40 +03:00
|
|
|
'urls' => [ 'Facebook' => $response->link ],
|
|
|
|
]);
|
2013-03-15 15:35:29 +04:00
|
|
|
|
|
|
|
return $user;
|
2013-01-29 20:08:47 +04:00
|
|
|
}
|
2013-09-14 06:21:42 +04:00
|
|
|
|
|
|
|
public function userUid($response, \League\OAuth2\Client\Token\AccessToken $token)
|
|
|
|
{
|
|
|
|
return $response->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userEmail($response, \League\OAuth2\Client\Token\AccessToken $token)
|
|
|
|
{
|
|
|
|
return isset($response->email) && $response->email ? $response->email : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userScreenName($response, \League\OAuth2\Client\Token\AccessToken $token)
|
|
|
|
{
|
2014-11-09 00:30:40 +03:00
|
|
|
return [$response->first_name, $response->last_name];
|
2013-09-14 06:21:42 +04:00
|
|
|
}
|
2013-01-29 20:06:24 +04:00
|
|
|
}
|