authentication.js 939 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* global WIKI */

// ------------------------------------
// GitLab Account
// ------------------------------------

const GitLabStrategy = require('passport-gitlab2').Strategy
const _ = require('lodash')

module.exports = {
  init (passport, conf) {
    passport.use('gitlab',
      new GitLabStrategy({
        clientID: conf.clientId,
        clientSecret: conf.clientSecret,
        callbackURL: conf.callbackURL,
Nick's avatar
Nick committed
17
        baseURL: conf.baseUrl,
18 19 20
        scope: ['read_user'],
        passReqToCallback: true
      }, async (req, accessToken, refreshToken, profile, cb) => {
21 22
        try {
          const user = await WIKI.models.users.processProfile({
23
            providerKey: req.params.strategy,
24 25 26
            profile: {
              ...profile,
              picture: _.get(profile, 'avatarUrl', '')
27
            }
28 29 30 31 32 33 34 35 36
          })
          cb(null, user)
        } catch (err) {
          cb(err, null)
        }
      }
      ))
  }
}