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

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

7
const TwitchStrategy = require('passport-twitch-oauth').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,
16 17 18
        callbackURL: conf.callbackURL,
        passReqToCallback: true
      }, async (req, accessToken, refreshToken, profile, cb) => {
Nick's avatar
Nick committed
19 20
        try {
          const user = await WIKI.models.users.processProfile({
21
            providerKey: req.params.strategy,
Nick's avatar
Nick committed
22 23
            profile: {
              ...profile,
24
              picture: _.get(profile, 'avatar', '')
25
            }
Nick's avatar
Nick committed
26 27 28 29 30
          })
          cb(null, user)
        } catch (err) {
          cb(err, null)
        }
31 32 33 34
      }
      ))
  }
}