wikijs-fork/server/modules/authentication/facebook/authentication.js

37 lines
992 B
JavaScript
Raw Permalink Normal View History

/* 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
module.exports = {
init (passport, conf) {
passport.use(conf.key,
new FacebookStrategy({
clientID: conf.clientId,
clientSecret: conf.clientSecret,
callbackURL: conf.callbackURL,
2019-04-28 06:11:38 +00:00
profileFields: ['id', 'displayName', 'email', 'photos'],
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({
providerKey: req.params.strategy,
2019-04-28 06:11:38 +00:00
profile: {
...profile,
picture: _.get(profile, 'photos[0].value', '')
}
2019-04-28 06:11:38 +00:00
})
cb(null, user)
} catch (err) {
cb(err, null)
}
}
))
}
2017-07-29 21:33:08 +00:00
}