authentication.js 829 Bytes
Newer Older
1
/* global WIKI */
2 3 4 5 6 7

// ------------------------------------
// Twitch Account
// ------------------------------------

const TwitchStrategy = require('passport-twitch').Strategy
Nick's avatar
Nick committed
8
const _ = require('lodash')
9 10 11 12 13 14 15

module.exports = {
  init (passport, conf) {
    passport.use('twitch',
      new TwitchStrategy({
        clientID: conf.clientId,
        clientSecret: conf.clientSecret,
Nick's avatar
Nick committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29
        callbackURL: conf.callbackURL
      }, async (accessToken, refreshToken, profile, cb) => {
        try {
          const user = await WIKI.models.users.processProfile({
            profile: {
              ...profile,
              picture: _.get(profile, '_json.logo', '')
            },
            providerKey: 'twitch'
          })
          cb(null, user)
        } catch (err) {
          cb(err, null)
        }
30 31 32 33
      }
      ))
  }
}