diff --git a/lib/server_fb.js b/lib/server_fb.js index bfb3439..bf3b236 100644 --- a/lib/server_fb.js +++ b/lib/server_fb.js @@ -53,7 +53,7 @@ exports.ParseSignedRequest = ParseSignedRequest; // locale: ISO local code f.ex. "en_US" // age: // min: years of age, typically 21 -var MainPageFlow = function(config, req, res) { +var CanvasPageFlow = function(config, req, res) { var signed_request = req.body.signed_request; if (signed_request == undefined) { @@ -68,8 +68,9 @@ var MainPageFlow = function(config, req, res) { // Using the canvas page itself as the login target, it will in turn catch the first if // and return to the facebook app page. // Also, we can't use protocol-relative URLS for redirection, Facebook errors with those. (?) + var redirect_url = /*CONFIG.CANVAS_PAGE*/ (req.connection.encrypted ? 'https' : 'http') + "://"+req.headers.host+req.url; var auth_url = "https://www.facebook.com/dialog/oauth?client_id=" + config.APP_ID - + "&redirect_uri=" + encodeURIComponent(/*CONFIG.CANVAS_PAGE*/ (req.connection.encrypted ? 'https' : 'http') + "://"+req.headers.host+req.url) + + "&redirect_uri=" + encodeURIComponent(redirect_url) + "&scope=" + config.FB_PERMISSIONS; res.send(""); return null; @@ -77,7 +78,7 @@ var MainPageFlow = function(config, req, res) { return request.payload_data; } -exports.MainPageFlow = MainPageFlow; +exports.CanvasPageFlow = CanvasPageFlow; // --------------- diff --git a/routes/index.js b/routes/index.js index 6aad401..1e743cc 100644 --- a/routes/index.js +++ b/routes/index.js @@ -44,7 +44,7 @@ exports.index = function(req, res) { + "\n cookies: " + JSON.stringify(req.cookies) + "\n request keys: " + JSON.stringify(Object.keys(req)));*/ - var payload = FB.MainPageFlow(CONFIG, req, res); + var payload = FB.CanvasPageFlow(CONFIG, req, res); if (!payload) return; diff --git a/static/js/client_fb.js b/static/js/client_fb.js index ae306e9..0b40dcd 100644 --- a/static/js/client_fb.js +++ b/static/js/client_fb.js @@ -6,12 +6,24 @@ Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php */ -FB_Init = function(app_id, fb_channel, cb) { - +FB_LoadSDK = function() { var fb_root = document.createElement('div'); fb_root.id = "fb-root"; document.body.appendChild(fb_root); + // Load the SDK Asynchronously + (function(d){ + var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} + js = d.createElement('script'); js.id = id; js.async = true; + js.src = "//connect.facebook.net/en_US/all.js"; + d.getElementsByTagName('head')[0].appendChild(js); + }(document)); +} + +FB_Init = function(app_id, fb_channel, cb) { + + FB_LoadSDK(); + window.fbAsyncInit = function() { FB.init({ appId : app_id, // App ID @@ -32,12 +44,6 @@ FB_Init = function(app_id, fb_channel, cb) { }); }); }; - - // Load the SDK Asynchronously - (function(d){ - var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} - js = d.createElement('script'); js.id = id; js.async = true; - js.src = "//connect.facebook.net/en_US/all.js"; - d.getElementsByTagName('head')[0].appendChild(js); - }(document)); + + } diff --git a/static/js/menu.js b/static/js/menu.js index d41e81d..aa1ee8c 100644 --- a/static/js/menu.js +++ b/static/js/menu.js @@ -8,7 +8,10 @@ EnterMenu = function() { LoadMenu(function(err, vars) { CONFIG.vars = vars; callback(err, vars);}); }, function(callback) { - FB.api('/'+CONFIG.me.id+'/picture', function(pic) { CONFIG.me_pic = pic; callback(null, pic);}); + //FB.api('/'+CONFIG.me.id+'/picture', function(pic) { CONFIG.me_pic = pic; callback(null, pic);}); + var pic = 'https://graph.facebook.com/' + CONFIG.me.id + '/picture'; + CONFIG.me_pic = pic; + callback(null, pic); }, function(callback) { $("#uicontainer").fadeOut('slow', function() { callback(null); });