summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2010-11-02 23:14:45 +0000
committerZach Copley <zach@status.net>2010-11-02 23:16:32 +0000
commit5ea04611450645e3b6b8c36627243e699be5f367 (patch)
treedd416dcfb1eacb597e0a33f8913db479ced3f6ae /plugins
parent764a297383ad8160b3e4d645d8953ef46a541b09 (diff)
Facebook SSO - Log the user out of Facebook when s/he logs out of StatusNet
Diffstat (limited to 'plugins')
-rw-r--r--plugins/FacebookSSO/FacebookSSOPlugin.php89
-rw-r--r--plugins/FacebookSSO/facebooklogin.php18
2 files changed, 81 insertions, 26 deletions
diff --git a/plugins/FacebookSSO/FacebookSSOPlugin.php b/plugins/FacebookSSO/FacebookSSOPlugin.php
index fca0275af..da109e9c4 100644
--- a/plugins/FacebookSSO/FacebookSSOPlugin.php
+++ b/plugins/FacebookSSO/FacebookSSOPlugin.php
@@ -68,7 +68,6 @@ class FacebookSSOPlugin extends Plugin
*/
function initialize()
{
- common_debug("XXXXXXXXXXXX " . $this->appId);
// Check defaults and configuration for application ID and secret
if (empty($this->appId)) {
$this->appId = common_config('facebook', 'appid');
@@ -79,7 +78,6 @@ class FacebookSSOPlugin extends Plugin
}
if (empty($this->facebook)) {
- common_debug('instantiating facebook obj');
$this->facebook = new Facebook(
array(
'appId' => $this->appId,
@@ -89,8 +87,6 @@ class FacebookSSOPlugin extends Plugin
);
}
- common_debug("FACEBOOK = " . var_export($this->facebook, true));
-
return true;
}
@@ -243,7 +239,7 @@ class FacebookSSOPlugin extends Plugin
}
/*
- * Add a tab for managing Facebook Connect settings
+ * Add a tab for user-level Facebook settings
*
* @param Action &action the current action
*
@@ -254,13 +250,14 @@ class FacebookSSOPlugin extends Plugin
if ($this->hasApplication()) {
$action_name = $action->trimmed('action');
- $action->menuItem(common_local_url('facebooksettings'),
- // @todo CHECKME: Should be 'Facebook Connect'?
- // TRANS: Menu item tab.
- _m('MENU','Facebook'),
- // TRANS: Tooltip for menu item "Facebook".
- _m('Facebook Connect Settings'),
- $action_name === 'facebooksettings');
+ $action->menuItem(
+ common_local_url('facebooksettings'),
+ // TRANS: Menu item tab.
+ _m('MENU','Facebook'),
+ // TRANS: Tooltip for menu item "Facebook".
+ _m('Facebook settings'),
+ $action_name === 'facebooksettings'
+ );
}
return true;
@@ -325,19 +322,75 @@ ENDOFSCRIPT;
return true;
}
+ /*
+ * Log the user out of Facebook, per the Facebook authentication guide
+ *
+ * @param Action action the action
+ */
+ function onEndLogout($action)
+ {
+ $session = $this->facebook->getSession();
+ $fbuser = null;
+ $fbuid = null;
+
+ if ($session) {
+ try {
+ $fbuid = $this->facebook->getUser();
+ $fbuser = $this->facebook->api('/me');
+ } catch (FacebookApiException $e) {
+ common_log(LOG_ERROR, $e, __FILE__);
+ }
+ }
+
+ if (!empty($fbuser)) {
+
+ $logoutUrl = $this->facebook->getLogoutUrl(
+ array('next' => common_local_url('public'))
+ );
+
+ common_log(
+ LOG_INFO,
+ sprintf(
+ "Logging user out of Facebook (fbuid = %s)",
+ $fbuid
+ ),
+ __FILE__
+ );
+
+ common_redirect($logoutUrl, 303);
+ }
+ }
+
+ /*
+ * Add fbml namespace so Facebook's JavaScript SDK can parse and render
+ * XFBML tags (e.g: <fb:login-button>)
+ *
+ * @param Action $action current action
+ * @param array $attrs array of attributes for the HTML tag
+ *
+ * @return nothing
+ */
function onStartHtmlElement($action, $attrs) {
$attrs = array_merge($attrs, array('xmlns:fb' => 'http://www.facebook.com/2008/fbml'));
return true;
}
+ /*
+ * Add version info for this plugin
+ *
+ * @param array &$versions plugin version descriptions
+ */
function onPluginVersion(&$versions)
{
- $versions[] = array('name' => 'Facebook Single-Sign-On',
- 'version' => STATUSNET_VERSION,
- 'author' => 'Zach Copley',
- 'homepage' => 'http://status.net/wiki/Plugin:FacebookSSO',
- 'rawdescription' =>
- _m('A plugin for single-sign-on with Facebook.'));
+ $versions[] = array(
+ 'name' => 'Facebook Single-Sign-On',
+ 'version' => STATUSNET_VERSION,
+ 'author' => 'Zach Copley',
+ 'homepage' => 'http://status.net/wiki/Plugin:FacebookSSO',
+ 'rawdescription' =>
+ _m('A plugin for single-sign-on with Facebook.')
+ );
+
return true;
}
}
diff --git a/plugins/FacebookSSO/facebooklogin.php b/plugins/FacebookSSO/facebooklogin.php
index fce481fc0..bb30be1af 100644
--- a/plugins/FacebookSSO/facebooklogin.php
+++ b/plugins/FacebookSSO/facebooklogin.php
@@ -20,7 +20,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
- * @category Pugin
+ * @category Plugin
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet, Inc.
@@ -34,6 +34,7 @@ if (!defined('STATUSNET')) {
class FacebookloginAction extends Action
{
+
function handle($args)
{
parent::handle($args);
@@ -53,7 +54,7 @@ class FacebookloginAction extends Action
);
$session = $facebook->getSession();
- $me = null;
+ $fbuser = null;
if ($session) {
try {
@@ -86,10 +87,11 @@ class FacebookloginAction extends Action
if (!empty($user)) {
- common_debug(
+ common_log(
+ LOG_INFO,
sprintf(
- 'Logged in Facebook user $s as user %d (%s)',
- $this->fbuid,
+ 'Logged in Facebook user %s as user %s (%s)',
+ $fbuid,
$user->id,
$user->nickname
),
@@ -150,9 +152,9 @@ class FacebookloginAction extends Action
$this->elementStart('fieldset');
$attrs = array(
- 'show-faces' => 'true',
- 'width' => '100',
- 'max-rows' => '2',
+ //'show-faces' => 'true',
+ //'max-rows' => '4',
+ //'width' => '600',
'perms' => 'user_location,user_website,offline_access,publish_stream'
);