2
0

authentication.js 892 B

12345678910111213141516171819202122232425262728293031323334
  1. /* global WIKI */
  2. // ------------------------------------
  3. // Slack Account
  4. // ------------------------------------
  5. const SlackStrategy = require('@aoberoi/passport-slack').default.Strategy
  6. const _ = require('lodash')
  7. module.exports = {
  8. init (passport, conf) {
  9. passport.use('slack',
  10. new SlackStrategy({
  11. clientID: conf.clientId,
  12. clientSecret: conf.clientSecret,
  13. callbackURL: conf.callbackURL,
  14. team: conf.team
  15. }, async (accessToken, scopes, team, extra, { user: userProfile }, cb) => {
  16. try {
  17. const user = await WIKI.models.users.processProfile({
  18. profile: {
  19. ...userProfile,
  20. picture: _.get(userProfile, 'image_48', '')
  21. },
  22. providerKey: 'slack'
  23. })
  24. cb(null, user)
  25. } catch (err) {
  26. cb(err, null)
  27. }
  28. }
  29. ))
  30. }
  31. }