Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJare committed Jun 15, 2014
1 parent 65fe0ea commit 1f746dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
7 changes: 4 additions & 3 deletions lib/server_fb.js
Expand Up @@ -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) {
Expand All @@ -68,16 +68,17 @@ 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("<script> top.location.href='" + auth_url + "'</script>");
return null;
}
return request.payload_data;
}

exports.MainPageFlow = MainPageFlow;
exports.CanvasPageFlow = CanvasPageFlow;


// ---------------
Expand Down
2 changes: 1 addition & 1 deletion routes/index.js
Expand Up @@ -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;

Expand Down
26 changes: 16 additions & 10 deletions static/js/client_fb.js
Expand Up @@ -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
Expand All @@ -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));


}
5 changes: 4 additions & 1 deletion static/js/menu.js
Expand Up @@ -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); });
Expand Down

0 comments on commit 1f746dc

Please sign in to comment.