2019-06-25 02:13:41 +00:00
|
|
|
/* global WIKI */
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// GitLab Account
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
const GitLabStrategy = require('passport-gitlab2').Strategy
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init (passport, conf) {
|
2022-03-26 01:17:04 +00:00
|
|
|
passport.use(conf.key,
|
2019-06-25 02:13:41 +00:00
|
|
|
new GitLabStrategy({
|
|
|
|
clientID: conf.clientId,
|
|
|
|
clientSecret: conf.clientSecret,
|
|
|
|
callbackURL: conf.callbackURL,
|
2019-07-24 01:21:24 +00:00
|
|
|
baseURL: conf.baseUrl,
|
2020-08-30 05:36:17 +00:00
|
|
|
scope: ['read_user'],
|
|
|
|
passReqToCallback: true
|
|
|
|
}, async (req, accessToken, refreshToken, profile, cb) => {
|
2019-06-25 02:13:41 +00:00
|
|
|
try {
|
|
|
|
const user = await WIKI.models.users.processProfile({
|
2020-08-30 05:36:17 +00:00
|
|
|
providerKey: req.params.strategy,
|
2019-06-25 02:13:41 +00:00
|
|
|
profile: {
|
|
|
|
...profile,
|
|
|
|
picture: _.get(profile, 'avatarUrl', '')
|
2020-08-30 05:36:17 +00:00
|
|
|
}
|
2019-06-25 02:13:41 +00:00
|
|
|
})
|
|
|
|
cb(null, user)
|
|
|
|
} catch (err) {
|
|
|
|
cb(err, null)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|