Commit e4d77cb9 authored by mmn's avatar mmn

Noone uses Facebook anymore.

parent 05a9c11c
This diff is collapsed.
Facebook Bridge Plugin
The Facebook Bridge plugin allows you to integrate your StatusNet site
with Facebook. It uses Facebook's new SDKs, the Graph API and OAuth
2.0, and supercedes the previous "Facebook" plugin, which relied on the
Facebook's now deprecated "Old REST API". The other major difference is
the troublesome and confusing Facebook Canvas Application has been
removed.
Note: Do NOT try to run the old Facebook plugin and this plugin at the same
time. It won't work.
Features for the new Facebook Bridge Plugin:
- "Login with Facebook" (AKA single-sign-on using Facebook Connect for
authentication).
- Registration with Facebook Connect, including automatic profile creation
based on users' Facebook accounts.
- Post mirroring -- posting a notice on StatusNet automatically creates a post
on Facebook, deleting it on StatusNet deletes it on Facebook, and faving it
"likes" it on Facebook.
Upgrading from the old Facebook plugin
======================================
Remove the addPlugin('Facebook') statement for the old Facebook plugin
from your config.php and adjust your existing Facebook application using
the setup instructions below as a guide, then enable the new plugin (also
described below). Existing users who have setup post mirroring shouldn't
have to do anything. The new Facebook Bridge plugin will keep their notices
flowing to Facebook.
Setup
=====
There are two parts configuring the Facebook Bridge plugin -- setup on the
Facebook side, and setup on the StatusNet side.
Setup (Facebook side)
=====================
The first step is to login to Facebook and register a Facebook application
to get an application ID and secret.
Use the handy Facebook application setup wizard:
http://developers.facebook.com/setup/
Once you've set up your application, you'll need to enter the Facebook Developer
dashboard (http://www.facebook.com/developers/editapp.php?app_id=YOUR_APPLICATION_ID)
and customize a few things:
About tab
---------
Set your logos, application description, etc. as you see fit.
Web Site tab
------------
Make a note of the "Application ID" and "Application Secret" Facebook generated
for your application. You'll need both of those later.
Make sure "Site URL" points to your StatusNet installation
(e.g.: http://example.net/).
- Special Note for multi-site Status Networks: enter your domain (SLD and TLD)
in the "Site Domain" field. (e.g.: status.net). This will allow a single
Facebook Application to work with all your network subdomains (*.status.net).
Facebook Integration tab
------------------------
Use the default settings.
Mobile and Devices tab
----------------------
Use the default settings.
Advanced tab
------------
In the Authentication section, set the "Deauthorize Callback" to
http://YOURSITE/facebook/deauthorize (e.g.: http://example.net/facebook/deauthorize).
In the Migrations section, ensure that "OAuth 2.0 for Canvas" is set to
"Enabled". It probably already will be, but double check.
The default settings should suffice for everything else.
Setup (StatusNet side)
======================
To enable the Facebook Bridge plugin, add
addPlugin('FacebookBridge');
to you config.php.
Next login to your StatusNet site as a user with the administrator role, and
navigate to the admin menu. You should see a new tab for the Facebook admin
panel, titled "Facebook". Enter your Facebook application ID and secret in
that admin panel and hit save. After that, the Facebook Bridge Plugin should
be ready to use.
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Facebook integration administration panel
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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 Settings
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
exit(1);
}
/**
* Administer global Facebook integration settings
*
* @category Admin
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
class FacebookadminpanelAction extends AdminPanelAction
{
/**
* Returns the page title
*
* @return string page title
*/
function title()
{
// TRANS: Title for Facebook administration panel.
return _m('TITLE','Facebook integration settings');
}
/**
* Instructions for using this form.
*
* @return string instructions
*/
function getInstructions()
{
// TRANS: Instruction for Facebook administration panel.
return _m('Facebook integration settings');
}
/**
* Show the Facebook admin panel form
*
* @return void
*/
function showForm()
{
$form = new FacebookAdminPanelForm($this);
$form->show();
return;
}
/**
* Save settings from the form
*
* @return void
*/
function saveSettings()
{
static $settings = array(
'facebook' => array('appid', 'secret'),
);
$values = array();
foreach ($settings as $section => $parts) {
foreach ($parts as $setting) {
$values[$section][$setting]
= $this->trimmed($setting);
}
}
// This throws an exception on validation errors
$this->validate($values);
// assert(all values are valid);
$config = new Config();
$config->query('BEGIN');
foreach ($settings as $section => $parts) {
foreach ($parts as $setting) {
Config::save($section, $setting, $values[$section][$setting]);
}
}
$config->query('COMMIT');
return;
}
function validate(&$values)
{
// appId, key and secret (can't be too long)
if (mb_strlen($values['facebook']['appid']) > 255) {
$this->clientError(
// TRANS: Client error displayed when providing too long a Facebook application ID.
_m("Invalid Facebook ID. Maximum length is 255 characters.")
);
}
if (mb_strlen($values['facebook']['secret']) > 255) {
$this->clientError(
// TRANS: Client error displayed when providing too long a Facebook secret key.
_m("Invalid Facebook secret. Maximum length is 255 characters.")
);
}
}
}
class FacebookAdminPanelForm extends AdminForm
{
/**
* ID of the form
*
* @return int ID of the form
*/
function id()
{
return 'facebookadminpanel';
}
/**
* class of the form
*
* @return string class of the form
*/
function formClass()
{
return 'form_settings';
}
/**
* Action of the form
*
* @return string URL of the action
*/
function action()
{
return common_local_url('facebookadminpanel');
}
/**
* Data elements of the form
*
* @return void
*/
function formData()
{
$this->out->elementStart(
'fieldset',
array('id' => 'settings_facebook-application')
);
// TRANS: Fieldset legend.
$this->out->element('legend', null, _m('Facebook application settings'));
$this->out->elementStart('ul', 'form_data');
$this->li();
$this->input(
'appid',
// TRANS: Field label for Facebook application ID.
_m('Application ID'),
// TRANS: Field title for Facebook application ID.
_m('ID of your Facebook application.'),
'facebook'
);
$this->unli();
$this->li();
$this->input(
'secret',
// TRANS: Field label for Facebook secret key.
_m('Secret'),
// TRANS: Field title for Facebook secret key.
_m('Application secret.'),
'facebook'
);
$this->unli();
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
}
/**
* Action elements
*
* @return void
*/
function formActions()
{
// TRANS: Button text to save Facebook integration settings.
$this->out->submit('submit', _m('BUTTON','Save'),
// TRANS: Button title to save Facebook integration settings.
'submit', null, _m('Save Facebook settings.'));
}
}
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010-2011, StatusNet, Inc.
*
* An action that handles deauthorize callbacks from Facebook
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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 Plugin
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2010-2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
exit(1);
}
/*
* Action class for handling deauthorize callbacks from Facebook. If the user
* doesn't have a password let her know she'll need to contact the site
* admin to get back into her account (if possible).
*/
class FacebookdeauthorizeAction extends Action
{
private $facebook;
/**
* For initializing members of the class.
*
* @param array $args misc. arguments
*
* @return boolean true
*/
function prepare(array $args = array())
{
$this->facebook = Facebookclient::getFacebook();
return true;
}
/**
* Handler method
*
* @param array $args is ignored since it's now passed in in prepare()
*/
function handle()
{
parent::handle();
$data = $this->facebook->getSignedRequest();
if (isset($data['user_id'])) {
$fbuid = $data['user_id'];
$flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
$user = $flink->getUser();
// Remove the link to Facebook
$result = $flink->delete();
if (!$result) {
common_log_db_error($flink, 'DELETE', __FILE__);
common_log(
LOG_WARNING,
sprintf(
'Unable to delete Facebook foreign link '
. 'for %s (%d), fbuid %d',
$user->nickname,
$user->id,
$fbuid
),
__FILE__
);
return;
}
common_log(
LOG_INFO,
sprintf(
'Facebook callback: %s (%d), fbuid %d has deauthorized '
. 'the Facebook application.',
$user->nickname,
$user->id,
$fbuid
),
__FILE__
);
// Warn the user about being locked out of their account
// if we can.
if (empty($user->password) && !empty($user->email)) {
Facebookclient::emailWarn($user);
} else {
common_log(
LOG_WARNING,
sprintf(
'%s (%d), fbuid %d has deauthorized his/her Facebook '
. 'connection but hasn\'t set a password so s/he '
. 'is locked out.',
$user->nickname,
$user->id,
$fbuid
),
__FILE__
);
}
} else {
if (!empty($data)) {
common_log(
LOG_WARNING,
sprintf(
'Facebook called the deauthorize callback '
. ' but didn\'t provide a user ID.'
),
__FILE__
);
} else {
// It probably wasn't Facebook that hit this action,
// so redirect to the public timeline
common_redirect(common_local_url('public'), 303);
}
}
}
}
This diff is collapsed.
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
*
* An action for logging in with Facebook
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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 Plugin
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2010-2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
exit(1);
}
class FacebookloginAction extends Action
{
function handle()
{
parent::handle();
if (common_is_real_login()) {
// TRANS: Client error displayed when trying to login while already logged in.
$this->clientError(_m('Already logged in.'));
} else {
$this->showPage();
}
}
function getInstructions()
{
// TRANS: Form instructions.
return _m('Login with your Facebook Account');
}
function showPageNotice()
{
$instr = $this->getInstructions();
$output = common_markup_to_html($instr);
$this->elementStart('div', 'instructions');
$this->raw($output);
$this->elementEnd('div');
}
function title()
{
// TRANS: Page title.
return _m('Login with Facebook');
}
function showContent() {
$this->elementStart('fieldset');
$facebook = Facebookclient::getFacebook();
$params = array(
'scope' => 'read_stream,publish_stream,offline_access,user_status,user_location,user_website,email',
'redirect_uri' => common_local_url('facebookfinishlogin')
);
// Degrade to plain link if JavaScript is not available
$this->elementStart(
'a',
array(
'href' => $facebook->getLoginUrl($params),
'id' => 'facebook_button'
)
);
$attrs = array(
'src' => Plugin::staticPath('FacebookBridge', 'images/login-button.png'),
// TRANS: Alt text for "Login with Facebook" image.
'alt' => _m('Login with Facebook'),
// TRANS: Title for "Login with Facebook" image.
'title' => _m('Login with Facebook.')
);
$this->element('img', $attrs);
$this->elementEnd('a');
$this->elementEnd('fieldset');
}
function showLocalNav()
{
$nav = new LoginGroupNav($this);
$nav->show();
}
}
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Edit user settings for Facebook
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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 Settings
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Edit user settings for Facebook
*
* @category Settings
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*
* @see SettingsAction
*/
class FacebooksettingsAction extends SettingsAction {
private $facebook; // Facebook PHP-SDK client obj
protected $flink;
protected function doPreparation()
{
$this->facebook = new Facebook(
array(
'appId' => common_config('facebook', 'appid'),
'secret' => common_config('facebook', 'secret'),
'cookie' => true,
)
);
$this->flink = Foreign_link::getByUserID(
$this->scoped->getID(),
FACEBOOK_SERVICE
);
}
protected function doPost()
{
if ($this->arg('save')) {
return $this->saveSettings();
} else if ($this->arg('disconnect')) {
return $this->disconnect();
}
throw new ClientException(_('No action to take on POST.'));
}
/**
* Returns the page title
*
* @return string page title
*/
function title() {
// TRANS: Page title for Facebook settings.
return _m('TITLE','Facebook settings');
}
/**
* Instructions for use
*
* @return instructions for use
*/
function getInstructions() {
// TRANS: Instructions for Facebook settings.
return _m('Facebook settings');
}
/*
* Show the settings form if he/she has a link to Facebook
*
* @return void
*/
function showContent() {
if (!$this->flink instanceof Foreign_link) {
throw new ServerException(_m('You have not linked this account to Facebook.'));
}