diff options
author | Jaime Pérez Crespo <jaime.perez@uninett.no> | 2016-07-29 08:04:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-29 08:04:57 +0200 |
commit | d8dc33c1b3c7aaf318401b0825889a4e77d65798 (patch) | |
tree | 9c477b4271a2386724242eb183a52d6f28ae44b2 | |
parent | 92abede5cf43463ffd9f162a56633b36821d86e5 (diff) | |
parent | 9a1d06cb036c9cf93aaa8150ec8634555668032b (diff) | |
download | simplesamlphp-d8dc33c1b3c7aaf318401b0825889a4e77d65798.zip simplesamlphp-d8dc33c1b3c7aaf318401b0825889a4e77d65798.tar.gz simplesamlphp-d8dc33c1b3c7aaf318401b0825889a4e77d65798.tar.bz2 |
Merge pull request #385 from grnet/bug/authfacebook-user-fields
Fix issue with Facebook authentication retrieving only user id and name
-rw-r--r-- | config-templates/authsources.php | 4 | ||||
-rw-r--r-- | modules/authfacebook/lib/Auth/Source/Facebook.php | 22 |
2 files changed, 23 insertions, 3 deletions
diff --git a/config-templates/authsources.php b/config-templates/authsources.php index a936f64..9f09ffd 100644 --- a/config-templates/authsources.php +++ b/config-templates/authsources.php @@ -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', ), */ diff --git a/modules/authfacebook/lib/Auth/Source/Facebook.php b/modules/authfacebook/lib/Auth/Source/Facebook.php index 5271f31..4961652 100644 --- a/modules/authfacebook/lib/Auth/Source/Facebook.php +++ b/modules/authfacebook/lib/Auth/Source/Facebook.php @@ -40,6 +40,21 @@ class sspmod_authfacebook_Auth_Source_Facebook extends SimpleSAML_Auth_Source { /** + * 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. * * @param array $info Information about 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'); } |