Last active
July 14, 2016 12:15
-
-
Save konsumer/2298cc4f8b7b0a1ee9fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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); | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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