authentication.js 998 B

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