2
2
/**
3
3
* Facebook strategy for Opauth
4
4
* based on https://developers.facebook.com/docs/authentication/server-side/
5
- *
5
+ *
6
6
* More information on Opauth: http://opauth.org
7
- *
7
+ *
8
8
* @copyright Copyright © 2012 U-Zyn Chua (http://uzyn.com)
9
9
* @link http://opauth.org
10
10
* @package Opauth.FacebookStrategy
11
11
* @license MIT License
12
12
*/
13
13
14
14
class FacebookStrategy extends OpauthStrategy{
15
-
15
+
16
16
/**
17
17
* Compulsory config keys, listed as unassociative arrays
18
18
* eg. array('app_id', 'app_secret');
19
19
*/
20
20
public $ expects = array ('app_id ' , 'app_secret ' );
21
-
21
+
22
22
/**
23
23
* Optional config keys with respective default values, listed as associative arrays
24
24
* eg. array('scope' => 'email');
@@ -42,10 +42,10 @@ public function request(){
42
42
if (!empty ($ this ->strategy ['response_type ' ])) $ params ['response_type ' ] = $ this ->strategy ['response_type ' ];
43
43
if (!empty ($ this ->strategy ['display ' ])) $ params ['display ' ] = $ this ->strategy ['display ' ];
44
44
if (!empty ($ this ->strategy ['auth_type ' ])) $ params ['auth_type ' ] = $ this ->strategy ['auth_type ' ];
45
-
45
+
46
46
$ this ->clientGet ($ url , $ params );
47
47
}
48
-
48
+
49
49
/**
50
50
* Internal callback, after Facebook's OAuth
51
51
*/
@@ -59,7 +59,7 @@ public function int_callback(){
59
59
'code ' => trim ($ _GET ['code ' ])
60
60
);
61
61
$ response = $ this ->serverGet ($ url , $ params , null , $ headers );
62
-
62
+
63
63
parse_str ($ response , $ results );
64
64
65
65
if (!empty ($ results ) && !empty ($ results ['access_token ' ])){
@@ -70,29 +70,27 @@ public function int_callback(){
70
70
'uid ' => $ me ->id ,
71
71
'info ' => array (
72
72
'name ' => $ me ->name ,
73
- 'image ' => 'https://graph.facebook.com/ ' .$ me ->id .'/picture?type=square '
73
+ 'image ' => 'https://graph.facebook.com/v2.6/ ' .$ me ->id .'/picture?type=large '
74
74
),
75
75
'credentials ' => array (
76
76
'token ' => $ results ['access_token ' ],
77
77
'expires ' => date ('c ' , time () + $ results ['expires ' ])
78
78
),
79
79
'raw ' => $ me
80
80
);
81
-
81
+
82
82
if (!empty ($ me ->email )) $ this ->auth ['info ' ]['email ' ] = $ me ->email ;
83
- if (!empty ($ me ->username )) $ this ->auth ['info ' ]['nickname ' ] = $ me ->username ;
83
+ if (!empty ($ me ->name )) $ this ->auth ['info ' ]['nickname ' ] = $ me ->name ;
84
84
if (!empty ($ me ->first_name )) $ this ->auth ['info ' ]['first_name ' ] = $ me ->first_name ;
85
85
if (!empty ($ me ->last_name )) $ this ->auth ['info ' ]['last_name ' ] = $ me ->last_name ;
86
- if (!empty ($ me ->location )) $ this ->auth ['info ' ]['location ' ] = $ me ->location ->name ;
87
86
if (!empty ($ me ->link )) $ this ->auth ['info ' ]['urls ' ]['facebook ' ] = $ me ->link ;
88
- if (!empty ($ me ->website )) $ this ->auth ['info ' ]['urls ' ]['website ' ] = $ me ->website ;
89
-
87
+
90
88
/**
91
89
* Missing optional info values
92
90
* - description
93
91
* - phone: not accessible via Facebook Graph API
94
92
*/
95
-
93
+
96
94
$ this ->callback ();
97
95
}
98
96
else {
@@ -113,19 +111,26 @@ public function int_callback(){
113
111
'message ' => $ _GET ['error_description ' ],
114
112
'raw ' => $ _GET
115
113
);
116
-
114
+
117
115
$ this ->errorCallback ($ error );
118
116
}
119
117
}
120
-
118
+
121
119
/**
122
120
* Queries Facebook Graph API for user info
123
121
*
124
- * @param string $access_token
122
+ * @param string $access_token
125
123
* @return array Parsed JSON results
126
124
*/
127
125
private function me ($ access_token ){
128
- $ me = $ this ->serverGet ('https://graph.facebook.com/me ' , array ('access_token ' => $ access_token ), null , $ headers );
126
+
127
+ $ fields = 'id,name,email ' ;//default value
128
+ if ( isset ($ this ->strategy ['fields ' ]) ) {
129
+ $ fields = $ this ->strategy ['fields ' ];
130
+ }
131
+
132
+ $ me = $ this ->serverGet ('https://graph.facebook.com/v2.6/me ' , array ('access_token ' => $ access_token , 'fields ' => $ fields ), null , $ headers );
133
+
129
134
if (!empty ($ me )){
130
135
return json_decode ($ me );
131
136
}
@@ -143,4 +148,4 @@ private function me($access_token){
143
148
$ this ->errorCallback ($ error );
144
149
}
145
150
}
146
- }
151
+ }
0 commit comments