2018-03-05 20:49:36 +00:00
|
|
|
/* global WIKI */
|
2017-07-29 21:33:08 +00:00
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Facebook Account
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
const FacebookStrategy = require('passport-facebook').Strategy
|
2019-04-28 06:11:38 +00:00
|
|
|
const _ = require('lodash')
|
2017-07-29 21:33:08 +00:00
|
|
|
|
2017-09-11 03:00:03 +00:00
|
|
|
module.exports = {
|
|
|
|
init (passport, conf) {
|
|
|
|
passport.use('facebook',
|
|
|
|
new FacebookStrategy({
|
|
|
|
clientID: conf.clientId,
|
|
|
|
clientSecret: conf.clientSecret,
|
|
|
|
callbackURL: conf.callbackURL,
|
2019-04-28 06:11:38 +00:00
|
|
|
profileFields: ['id', 'displayName', 'email', 'photos'],
|
2020-08-30 05:36:17 +00:00
|
|
|
authType: 'reauthenticate',
|
|
|
|
passReqToCallback: true
|
|
|
|
}, async (req, accessToken, refreshToken, profile, cb) => {
|
2019-04-28 06:11:38 +00:00
|
|
|
try {
|
|
|
|
const user = await WIKI.models.users.processProfile({
|
2020-08-30 05:36:17 +00:00
|
|
|
providerKey: req.params.strategy,
|
2019-04-28 06:11:38 +00:00
|
|
|
profile: {
|
|
|
|
...profile,
|
|
|
|
picture: _.get(profile, 'photos[0].value', '')
|
2020-08-30 05:36:17 +00:00
|
|
|
}
|
2019-04-28 06:11:38 +00:00
|
|
|
})
|
|
|
|
cb(null, user)
|
|
|
|
} catch (err) {
|
|
|
|
cb(err, null)
|
|
|
|
}
|
2017-09-11 03:00:03 +00:00
|
|
|
}
|
|
|
|
))
|
|
|
|
}
|
2017-07-29 21:33:08 +00:00
|
|
|
}
|