Skip to content

Commit

Permalink
fix(fb): Update Facebook login SDK (#454)
Browse files Browse the repository at this point in the history
Addresses:

- "Your Facebook SDK is out-of-date. Please upgrade to v5.0 for access to new privacy features." banner from https://developers.facebook.com/apps/169250156435902/dashboard/
- "App Inactive for More Than 90 Days" banner from https://developers.facebook.com/apps/118010211606360/dashboard/ and https://developers.facebook.com/apps/1059973490696893/dashboard/ (old *development* fb apps)

May also contribute to #370.

Changes:

* 🧹 remove old facebook app: 1059973490696893

* lint: declare db and ObjectId as globals

* scout rule: don't throw from a callback function

* troubleshoot: display logs of mongodb-shell-runner

* fix(mongodb-shell-runner): ignore multi-line blocks of comments

* fix "Feature Unavailable: Facebook Login is currently unavailable for this app" when trying to signup with facebook from localhost
=> use "development app", forked from main/production facebook app

* also chage facebook app id in mainTemplate

* use version 10 of the graph API, as specified in the "Upgrade API Version" of https://developers.facebook.com/apps/1573219269412628/settings/advanced/

* add note about old fb app id
  • Loading branch information
adrienjoly committed May 14, 2021
1 parent bb2a7bc commit 987ce00
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/models/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports.graphApiRequest = function (fbAccessToken, path, params, handler) {
params.access_token = fbAccessToken;
params.metadata = !!params.metadata;
params.method = params.method || 'GET';
var url = '/v2.3' + path + '?' + querystring.stringify(params);
var url = path + '?' + querystring.stringify(params);
https
.request(
{ path: url, host: host, port: 443, method: params.method },
Expand Down
10 changes: 8 additions & 2 deletions app/models/mongodb-shell-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ exports.runScriptOnDatabase = function (script, db, callback) {
async.eachSeries(
commands,
function (command, nextCommand) {
command = command.trim();
if (!command || /^\/\//.test(command) || /^\/\*.*\*\/$/.test(command)) {
const cleaned = command
.split(/[\r\n]+/g) // split lines
.map((line) => line.replace(/\/\/.*/, '')) // remove // comments
.join(' ') // join lines as one
.replace(/[\r\n]+/g, '') // remove line breaks, so that multiple lines of comments == ""
.replace(/\/\*.*\*\//g, '') // remove /**/ comments
.trim();
if (!cleaned) {
VERBOSE && console.log(LOG_PREFIX, 'IGN', command);
nextCommand();
} else {
Expand Down
4 changes: 2 additions & 2 deletions app/models/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ exports.initCollections = function ({ addTestData } = {}) {
function (initScript, nextScript) {
console.log('[db] Applying db init script:', initScript, '...');
exports.runShellScript(fs.readFileSync(initScript), function (err) {
if (err) throw err;
nextScript();
if (err) console.error(err);
nextScript(err);
});
},
function (err) {
Expand Down
7 changes: 1 addition & 6 deletions app/templates/mainTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@ if (isProduction) {
//console.log('- Production - ');
fbId = '169250156435902';
playemFile = 'min';
} else if (config.urlPrefix.indexOf('whyd.fr') > 0) {
// pre-production
//console.log('- Test - ');
fbId = '1059973490696893';
playemFile = 'all';
} else {
//console.log('- Local - ');
fbId = '118010211606360';
fbId = '1573219269412628';
playemFile = 'all';
}

Expand Down
2 changes: 2 additions & 0 deletions config/initdb_testing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* globals db, ObjectId */

// Usage: this file should be run by runShellScript() or by mongo's CLI:
// $ mongo openwhyd_data initdb_testing.js

Expand Down
1 change: 1 addition & 0 deletions cypress/fixtures/users.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
({
// TODO: make sure that this data remains in sync with what's add in the db, in initdb_testing.js
admin: {
id: '000000000000000000000001',
email: process.env.WHYD_ADMIN_EMAIL || 'test@openwhyd.org',
Expand Down
2 changes: 1 addition & 1 deletion public/html/testFbInvite.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// pre-production
fbId = '1059973490696893';
} else {
fbId = '118010211606360';
fbId = '118010211606360'; // note: this "openwhyd-dev" app was deleted on 14/05/2021, in favor of test app id 1573219269412628
}

window.user = { id: '4d94501d1f78ac091dbc9b4d', name: 'Adrien Joly' };
Expand Down
27 changes: 9 additions & 18 deletions public/js/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ var fbId;
if (href.indexOf('openwhyd.org/') > 0) {
// namespace = 'whydapp';
fbId = '169250156435902';
} /*else if (href.indexOf('whyd.fr/') > 0) {
// pre-production
namespace = 'whyd-test';
fbId = '1059973490696893';
} */ else {
} else {
// namespace = 'whyd-dev';
fbId = '118010211606360';
fbId = '1573219269412628';
}

var facebookPerms = 'public_profile,email';
Expand Down Expand Up @@ -147,10 +143,8 @@ globals.fbRegister = function (perms, cb) {
globals.fbAsyncInit = function () {
globals.FB.init({
appId: fbId,
version: 'v2.3',
status: true,
version: 'v10.0',
cookie: true,
oauth: true,
xfbml: true,
});
globals.whenFbReady = function (fct) {
Expand All @@ -172,17 +166,14 @@ globals.whenFbReady(function () {
});

// Load the SDK Asynchronously
(function (d) {
/*if (!d.getElementById("fb-root"))
d.getElementsByTagName('body')[0].appendChild(d.createElement('div')).id = "fb-root";*/
(function (d, s, id) {
var js,
id = 'facebook-jssdk';
fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js = d.createElement(s);
js.id = id;
js.async = true;
js.src = '//connect.facebook.net/en_US/sdk.js';
d.getElementsByTagName('head')[0].appendChild(js);
})(document);
js.src = 'https://connect.facebook.net/en_US/sdk.js';
fjs.parentNode.insertBefore(js, fjs);
})(document, 'script', 'facebook-jssdk');

0 comments on commit 987ce00

Please sign in to comment.