authentication.js 910 B

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