You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
939 B

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