mirror of https://github.com/Requarks/wiki.git
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.
38 lines
993 B
38 lines
993 B
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,
|
|
userInfoURL: conf.userInfoURL,
|
|
callbackURL: conf.callbackURL
|
|
}, 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)
|
|
}
|
|
})
|
|
)
|
|
}
|
|
}
|