Last active
June 24, 2018 07:44
-
-
Save AndrejGajdos/1599721deaa4ec4d777b4d51fd51b433 to your computer and use it in GitHub Desktop.
Passport facebook strategy. Whole file is available https://github.com/AndrejGajdos/auth-flow-spa-node-react/blob/master/script/controllers/auth.js
This file contains hidden or 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
passport.use( | |
new FacebookStrategy( | |
{ | |
clientID: config.facebookAuth.clientID, | |
clientSecret: config.facebookAuth.clientSecret, | |
callbackURL: config.facebookAuth.callbackURL, | |
profileFields: [ | |
'id', | |
'displayName', | |
'picture.width(200).height(200)', | |
'first_name', | |
'middle_name', | |
'last_name', | |
'email', | |
], | |
}, | |
(accessToken, refreshToken, profile, done) => { | |
process.nextTick(async () => { | |
const facebookUser = { | |
id: Math.random(), | |
userName: profile.displayName, | |
email: profile.emails[0].value, | |
imgUrl: profile.photos[0].value, | |
imgHeight: 200, | |
imgWidth: 200, | |
userProfileId: profile.id, | |
}; | |
await getAsync('usersMockDatabase').then((users) => { | |
// save new user into database | |
const currUsers = JSON.parse(users); | |
currUsers.push(facebookUser); | |
db.set('usersMockDatabase', JSON.stringify(currUsers)); | |
}); | |
return done(null, facebookUser); | |
}); | |
}, | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment