50 lines
1.3 KiB
PHP
Executable File
50 lines
1.3 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Facebook OAuth2 Provider
|
|
*
|
|
* @package CodeIgniter/OAuth2
|
|
* @category Provider
|
|
* @author Phil Sturgeon
|
|
* @copyright (c) 2012 HappyNinjas Ltd
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
|
*/
|
|
|
|
class Facebook extends OAuth2\Client\IDP
|
|
{
|
|
protected $scope = array('offline_access', 'email', 'read_stream');
|
|
|
|
public function urlAuthorize()
|
|
{
|
|
return 'https://www.facebook.com/dialog/oauth';
|
|
}
|
|
|
|
public function urlAccessToken()
|
|
{
|
|
return 'https://graph.facebook.com/oauth/access_token';
|
|
}
|
|
|
|
public function getUserInfo(OAuth2\Token\Access $token)
|
|
{
|
|
$url = 'https://graph.facebook.com/me?'.http_build_query(array(
|
|
'access_token' => $token->access_token,
|
|
));
|
|
|
|
$user = json_decode(file_get_contents($url));
|
|
|
|
return array(
|
|
'uid' => $user->id,
|
|
'nickname' => isset($user->username) ? $user->username : null,
|
|
'name' => $user->name,
|
|
'first_name' => $user->first_name,
|
|
'last_name' => $user->last_name,
|
|
'email' => isset($user->email) ? $user->email : null,
|
|
'location' => isset($user->hometown->name) ? $user->hometown->name : null,
|
|
'description' => isset($user->bio) ? $user->bio : null,
|
|
'image' => 'https://graph.facebook.com/me/picture?type=normal&access_token='.$token->access_token,
|
|
'urls' => array(
|
|
'Facebook' => $user->link,
|
|
),
|
|
);
|
|
}
|
|
}
|