Last active
July 8, 2019 07:55
-
-
Save christianstrang/ec77d9ecc7520f3a33cfcce38ff6a24e 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
'use strict'; | |
var passport = require('passport'), | |
FacebookStrategy = require('passport-facebook').Strategy, | |
request = require('request'); | |
var verifyHandler = function(req, token, tokenSecret, profile, done) { | |
process.nextTick(function() { | |
var url = 'https://graph.facebook.com/v2.10/me?access_token=%s&fields=id,name,email,first_name,last_name'; | |
url = url.replace('%s', token); | |
var options = {method: 'GET', url: url, json: true}; | |
request(options, function (err, response) { | |
if (err) { | |
return done(null, null); | |
} | |
var data = { | |
id: response.body.id, | |
first_name: response.body.first_name, //jshint ignore:line | |
last_name: response.body.last_name, //jshint ignore:line | |
email: response.body.email, | |
gender: response.body.gender | |
}; | |
console.log(data); | |
return done(null, data); | |
}); | |
}); | |
}; | |
passport.use(new FacebookStrategy({ | |
clientID: FACEBOOK_CLIENT_ID, | |
clientSecret: FACEBOOK_APP_SECRET, | |
callbackURL: FACEBOOK_CALLBACK_URL, | |
passReqToCallback: true | |
}, verifyHandler)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment