authentication.js 988 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* global WIKI */
  2. // ------------------------------------
  3. // Facebook Account
  4. // ------------------------------------
  5. const FacebookStrategy = require('passport-facebook').Strategy
  6. const _ = require('lodash')
  7. module.exports = {
  8. init (passport, conf) {
  9. passport.use(conf.key,
  10. new FacebookStrategy({
  11. clientID: conf.clientId,
  12. clientSecret: conf.clientSecret,
  13. callbackURL: conf.callbackURL,
  14. profileFields: ['id', 'displayName', 'email', 'photos'],
  15. authType: 'reauthenticate',
  16. passReqToCallback: true
  17. }, async (req, accessToken, refreshToken, profile, cb) => {
  18. try {
  19. const user = await WIKI.db.users.processProfile({
  20. providerKey: req.params.strategy,
  21. profile: {
  22. ...profile,
  23. picture: _.get(profile, 'photos[0].value', '')
  24. }
  25. })
  26. cb(null, user)
  27. } catch (err) {
  28. cb(err, null)
  29. }
  30. }
  31. ))
  32. }
  33. }