2018-08-04 21:27:55 +00:00
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
/* global WIKI */
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// OpenID Connect Account
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
const OpenIDConnectStrategy = require('passport-openidconnect').Strategy
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init (passport, conf) {
|
|
|
|
passport.use('oidc',
|
|
|
|
new OpenIDConnectStrategy({
|
|
|
|
authorizationURL: conf.authorizationURL,
|
|
|
|
tokenURL: conf.tokenURL,
|
|
|
|
clientID: conf.clientId,
|
|
|
|
clientSecret: conf.clientSecret,
|
|
|
|
issuer: conf.issuer,
|
2020-08-15 17:32:58 +00:00
|
|
|
userInfoURL: conf.userInfoURL,
|
2020-08-30 05:36:17 +00:00
|
|
|
callbackURL: conf.callbackURL,
|
|
|
|
passReqToCallback: true
|
|
|
|
}, async (req, iss, sub, profile, cb) => {
|
2020-08-15 17:32:58 +00:00
|
|
|
try {
|
|
|
|
const user = await WIKI.models.users.processProfile({
|
2020-08-30 05:36:17 +00:00
|
|
|
providerKey: req.params.strategy,
|
2020-08-15 17:32:58 +00:00
|
|
|
profile: {
|
|
|
|
...profile,
|
|
|
|
email: _.get(profile, '_json.' + conf.emailClaim)
|
2020-08-30 05:36:17 +00:00
|
|
|
}
|
2020-08-15 17:32:58 +00:00
|
|
|
})
|
|
|
|
cb(null, user)
|
2020-08-30 05:36:17 +00:00
|
|
|
} catch (err) {
|
2020-08-15 17:32:58 +00:00
|
|
|
cb(err, null)
|
|
|
|
}
|
2018-08-04 21:27:55 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|