2018-03-05 20:49:36 +00:00
|
|
|
/* global WIKI */
|
2017-07-29 21:33:08 +00:00
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Google ID Account
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
const GoogleStrategy = require('passport-google-oauth20').Strategy
|
2019-04-28 04:20:06 +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('google',
|
|
|
|
new GoogleStrategy({
|
|
|
|
clientID: conf.clientId,
|
|
|
|
clientSecret: conf.clientSecret,
|
2020-08-30 05:36:17 +00:00
|
|
|
callbackURL: conf.callbackURL,
|
|
|
|
passReqToCallback: true
|
|
|
|
}, async (req, accessToken, refreshToken, profile, cb) => {
|
2019-04-28 04:20:06 +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 04:20:06 +00:00
|
|
|
profile: {
|
|
|
|
...profile,
|
|
|
|
picture: _.get(profile, 'photos[0].value', '')
|
2020-08-30 05:36:17 +00:00
|
|
|
}
|
2019-04-28 04:20:06 +00:00
|
|
|
})
|
|
|
|
cb(null, user)
|
|
|
|
} catch (err) {
|
|
|
|
cb(err, null)
|
|
|
|
}
|
2017-12-30 07:00:49 +00:00
|
|
|
})
|
|
|
|
)
|
2017-09-11 03:00:03 +00:00
|
|
|
}
|
2017-07-29 21:33:08 +00:00
|
|
|
}
|