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,
|
2018-08-04 21:27:55 +00:00
|
|
|
callbackURL: conf.callbackURL
|
2020-08-15 17:32:58 +00:00
|
|
|
}, async (iss, sub, profile, cb) => {
|
|
|
|
try {
|
|
|
|
const user = await WIKI.models.users.processProfile({
|
|
|
|
profile: {
|
|
|
|
...profile,
|
|
|
|
email: _.get(profile, '_json.' + conf.emailClaim)
|
|
|
|
},
|
|
|
|
providerKey: 'oidc'
|
|
|
|
})
|
|
|
|
cb(null, user)
|
|
|
|
} catch(err) {
|
|
|
|
cb(err, null)
|
|
|
|
}
|
2018-08-04 21:27:55 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|