authfacebook: Fix facebook authentication source.

This patch also changes the facebook authentication source to behave
more like the openid authentication source wrt. attribute naming.

Thanks to Brook Schofield for providing this patch!

git-svn-id: http://simplesamlphp.googlecode.com/svn/trunk@2655 44740490-163a-0410-bde0-09ae8108e29a
This commit is contained in:
olavmrk 2010-11-25 10:27:04 +00:00
parent 0898064cad
commit 21a9b10472
3 changed files with 41 additions and 10 deletions

View File

@ -0,0 +1,21 @@
<?php
$attributemap = array(
// Generated Facebook Attributes
'facebook_user' => 'eduPersonPrincipalName', // username OR uid @ facebook.com
'facebook_targetedID' => 'eduPersonTargetedID', // http://facebook.com!uid
'facebook_cn' => 'cn', // duplicate of displayName
// Attributes Returned by Facebook
'facebook.first_name' => 'givenName',
'facebook.last_name' => 'sn',
'facebook.name' => 'displayName', // or 'cn'
'facebook.email' => 'mail',
//'facebook.pic' => 'jpegPhoto', // URL not image data
//'facebook.pic_square' => 'jpegPhoto', // URL not image data
'facebook.username' => 'uid', // facebook username (maybe blank)
//'facebook.uid' => 'uid', // numeric facebook user id
'facebook.profile_url' => 'labeledURI',
'facebook.locale' => 'preferredLanguage',
'facebook.about_me' => 'description',
);

View File

@ -217,6 +217,7 @@ class Facebook {
public function get_login_url($next, $canvas) {
return self::get_facebook_url().'/login.php?v=1.0&api_key=' . $this->api_key .
($next ? '&next=' . urlencode($next) : '') .
'&req_perms=email' .
($canvas ? '&canvas' : '');
}

View File

@ -70,23 +70,32 @@ class sspmod_authfacebook_Auth_Source_Facebook extends SimpleSAML_Auth_Source {
SimpleSAML_Logger::debug('facebook auth state id = ' . $stateID);
$facebook = new Facebook($this->api_key, $this->secret);
$u = $facebook->require_login($stateID);
$u = $facebook->require_login(SimpleSAML_Module::getModuleUrl('authfacebook') . '/linkback.php?next=' . $stateID);
# http://developers.facebook.com/documentation.php?v=1.0&method=users.getInfo
/* Causes an notice / warning...
if ($facebook->api_client->error_code) {
throw new Exception('Unable to load profile from facebook');
}
*/
$info = $facebook->api_client->users_getInfo($u, array('first_name', 'last_name'));
$fullname = $info[0]['first_name'] .' '. $info[0]['last_name'];
// http://developers.facebook.com/docs/reference/rest/users.getInfo
$info = $facebook->api_client->users_getInfo($u, array('uid', 'first_name', 'middle_name', 'last_name', 'name', 'locale', 'current_location', 'affiliations', 'pic_square', 'profile_url', 'sex', 'email', 'pic', 'username', 'about_me', 'status', 'profile_blurb'));
$attributes = array(
'sn' => array($info[0]['last_name']),
'givenName' => array($info[0]['first_name']),
'cn' => array($info[0]['first_name'] .' '. $info[0]['last_name']),
'uid' => array($u),
'eduPersonPrincipalName' => array('facebook:' . $u),
);
$attributes = array();
foreach($info[0] AS $key => $value) {
if (is_string($value) && !empty($value))
$attributes['facebook.' . $key] = array((string)$value);
}
if (array_key_exists('username', $info[0]) )
$attributes['facebook_user'] = array($info[0]['username'] . '@facebook.com');
else
$attributes['facebook_user'] = array($u . '@facebook.com');
$attributes['facebook_targetedID'] = array('http://facebook.com!' . $u);
$attributes['facebook_cn'] = array($info[0]['name']);
SimpleSAML_Logger::debug('Facebook Returned Attributes: '. implode(", ",array_keys($attributes)));
$state['Attributes'] = $attributes;
}