Skip to content
Snippets Groups Projects
Commit d8dc33c1 authored by Jaime Pérez Crespo's avatar Jaime Pérez Crespo Committed by GitHub
Browse files

Merge pull request #385 from grnet/bug/authfacebook-user-fields

Fix issue with Facebook authentication retrieving only user id and name
parents 92abede5 9a1d06cb
No related branches found
No related tags found
No related merge requests found
......@@ -201,6 +201,10 @@ $config = array(
// which additional data permissions to request from user
// see http://developers.facebook.com/docs/authentication/permissions/ for the full list
// 'req_perms' => 'email,user_birthday',
// Which additional user profile fields to request.
// When empty, only the app-specific user id and name will be returned
// See https://developers.facebook.com/docs/graph-api/reference/v2.6/user for the full list
// 'user_fields' => 'email,birthday,third_party_id,name,first_name,last_name',
),
*/
......
......@@ -39,6 +39,21 @@ class sspmod_authfacebook_Auth_Source_Facebook extends SimpleSAML_Auth_Source {
private $req_perms;
/**
* A comma-separated list of user profile fields to request.
*
* Note that some user fields require appropriate permissions. For
* example, to retrieve the user's primary email address, "email" must
* be specified in both the req_perms and the user_fields parameter.
*
* When empty, only the app-specific user id and name will be returned.
*
* See the Graph API specification for all available user fields:
* https://developers.facebook.com/docs/graph-api/reference/v2.6/user
*/
private $user_fields;
/**
* Constructor for this authentication source.
*
......@@ -57,6 +72,7 @@ class sspmod_authfacebook_Auth_Source_Facebook extends SimpleSAML_Auth_Source {
$this->api_key = $cfgParse->getString('api_key');
$this->secret = $cfgParse->getString('secret');
$this->req_perms = $cfgParse->getString('req_perms', NULL);
$this->user_fields = $cfgParse->getString('user_fields', NULL);
}
......@@ -91,7 +107,7 @@ class sspmod_authfacebook_Auth_Source_Facebook extends SimpleSAML_Auth_Source {
if (isset($uid) && $uid) {
try {
$info = $facebook->api("/" . $uid);
$info = $facebook->api("/" . $uid . ($this->user_fields ? "?fields=" . $this->user_fields : ""));
} catch (FacebookApiException $e) {
throw new SimpleSAML_Error_AuthSource($this->authId, 'Error getting user profile.', $e);
}
......@@ -108,8 +124,8 @@ class sspmod_authfacebook_Auth_Source_Facebook extends SimpleSAML_Auth_Source {
}
}
if (array_key_exists('username', $info)) {
$attributes['facebook_user'] = array($info['username'] . '@facebook.com');
if (array_key_exists('third_party_id', $info)) {
$attributes['facebook_user'] = array($info['third_party_id'] . '@facebook.com');
} else {
$attributes['facebook_user'] = array($uid . '@facebook.com');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment