Skip to content

Instantly share code, notes, and snippets.

@konsumer
Last active July 14, 2016 12:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konsumer/2298cc4f8b7b0a1ee9fa to your computer and use it in GitHub Desktop.
Save konsumer/2298cc4f8b7b0a1ee9fa to your computer and use it in GitHub Desktop.
/**
Client-side facebook login for nodewebkit
**/
var url = require('url');
module.exports = function (client_id, app_url, callback){
var loginWindow = window.open('https://www.facebook.com/dialog/oauth?response_type=token&client_id=' + client_id + '&redirect_uri=' + app_url, 'Login facebook', false);
var out = {};
loginWindow.addEventListener('load', function(){
url.parse(loginWindow.document.URL).hash.substring(1).split('&').forEach(function(p){
var a = p.split('=');
out[ a[0] ] = a[1];
});
if (out.access_token){
loginWindow.close();
callback(out);
}
});
};
var facebookLogin = require('./nwFacebookLogin.js');
var facebook_id = 'YOUR_APP_ID';
var app_url = 'YOUR_APP_URL';
facebookLogin(facebook_id, app_url, function(res){
console.log(res);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment