Created
July 9, 2019 07:50
-
-
Save christianstrang/5d58c309d68ef2368b7def797953889d to your computer and use it in GitHub Desktop.
SailsJS FacebookStrategy for Passport
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,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, | |
last_name: response.body.last_name, | |
email: response.body.email | |
}; | |
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