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

35 lines
892 B
JavaScript
Raw Normal View History

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