Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
10582 lgm 1
<?php
2
/**
3
 * Facebook OAuth2 Provider
4
 *
5
 * @package    CodeIgniter/OAuth2
6
 * @category   Provider
7
 * @author     Phil Sturgeon
8
 * @copyright  (c) 2012 HappyNinjas Ltd
9
 * @license    http://philsturgeon.co.uk/code/dbad-license
10
 */
11
 
12
class OAuth2_Provider_Facebook extends OAuth2_Provider
13
{
14
	protected $scope = array('offline_access', 'email', 'read_stream');
15
 
16
	public function url_authorize()
17
	{
18
		return 'https://www.facebook.com/dialog/oauth';
19
	}
20
 
21
	public function url_access_token()
22
	{
23
		return 'https://graph.facebook.com/oauth/access_token';
24
	}
25
 
26
	public function get_user_info(OAuth2_Token_Access $token)
27
	{
28
		$url = 'https://graph.facebook.com/me?'.http_build_query(array(
29
			'access_token' => $token->access_token,
30
		));
31
 
32
		$ch = curl_init($url);                                                                      
33
				curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");                                                                   
34
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
35
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
36
		$user = json_decode(curl_exec($ch), true);
37
		// Create a response from the request
38
		return array(
39
			'uid' => $user['id'],
40
			'nickname' => isset($user['username']) ? $user['username'] : null,
41
			'name' => $user['name'],
42
			'first_name' => $user['first_name'],
43
			'last_name' => $user['last_name'],
44
			'email' => isset($user['email']) ? $user['email'] : null,
45
			'location' => isset($user['hometown']['name']) ? $user['hometown']['name'] : null,
46
			'description' => isset($user['bio']) ? $user['bio'] : null,
47
			'image' => 'https://graph.facebook.com/me/picture?type=normal&access_token='.$token->access_token,
48
			'urls' => array(
49
			  'Facebook' => $user['link'],
50
			),
51
			'loginType'=>'facebook',
52
			'access_token'=>$token->access_token,
53
		);
54
	}
55
}