123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- const _ = require('lodash')
- /* global WIKI */
- // ------------------------------------
- // OpenID Connect Account
- // ------------------------------------
- const OpenIDConnectStrategy = require('passport-openidconnect').Strategy
- module.exports = {
- init (passport, conf) {
- passport.use(conf.key,
- new OpenIDConnectStrategy({
- authorizationURL: conf.authorizationURL,
- tokenURL: conf.tokenURL,
- clientID: conf.clientId,
- clientSecret: conf.clientSecret,
- issuer: conf.issuer,
- userInfoURL: conf.userInfoURL,
- callbackURL: conf.callbackURL,
- passReqToCallback: true
- }, async (req, iss, sub, profile, cb) => {
- try {
- const user = await WIKI.models.users.processProfile({
- providerKey: req.params.strategy,
- profile: {
- ...profile,
- email: _.get(profile, '_json.' + conf.emailClaim)
- }
- })
- if (conf.mapGroups) {
- const groups = _.get(profile, '_json.' + conf.groupsClaim)
- if (groups) {
- const groupIDs = Object.values(WIKI.auth.groups)
- .filter(g => groups.includes(g.name))
- .map(g => g.id)
- for (let groupID of groupIDs) {
- await user.$relatedQuery('groups').relate(groupID)
- }
- }
- }
- cb(null, user)
- } catch (err) {
- cb(err, null)
- }
- })
- )
- },
- logout (conf) {
- if (!conf.logoutURL) {
- return '/'
- } else {
- return conf.logoutURL
- }
- }
- }
|