You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
843 B

  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. }, async (accessToken, refreshToken, profile, cb) => {
  15. try {
  16. const user = await WIKI.models.users.processProfile({
  17. profile: {
  18. ...profile,
  19. picture: _.get(profile, 'photos[0].value', '')
  20. },
  21. providerKey: 'google'
  22. })
  23. cb(null, user)
  24. } catch (err) {
  25. cb(err, null)
  26. }
  27. })
  28. )
  29. }
  30. }