2
0

authentication.js 930 B

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