authentication.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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(conf.key,
  10. new GitLabStrategy({
  11. clientID: conf.clientId,
  12. clientSecret: conf.clientSecret,
  13. callbackURL: conf.callbackURL,
  14. baseURL: conf.baseUrl,
  15. authorizationURL: conf.authorizationURL || (conf.baseUrl + '/oauth/authorize'),
  16. tokenURL: conf.tokenURL || (conf.baseUrl + '/oauth/token'),
  17. scope: ['read_user'],
  18. passReqToCallback: true
  19. }, async (req, accessToken, refreshToken, profile, cb) => {
  20. try {
  21. const user = await WIKI.models.users.processProfile({
  22. providerKey: req.params.strategy,
  23. profile: {
  24. ...profile,
  25. picture: _.get(profile, 'avatarUrl', '')
  26. }
  27. })
  28. cb(null, user)
  29. } catch (err) {
  30. cb(err, null)
  31. }
  32. }
  33. ))
  34. }
  35. }