2022-07-16 23:41:41 +00:00
|
|
|
const _ = require('lodash')
|
2018-07-08 15:16:45 +00:00
|
|
|
/* global WIKI */
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// CAS Account
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
const CASStrategy = require('passport-cas').Strategy
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init (passport, conf) {
|
2022-03-26 01:17:04 +00:00
|
|
|
passport.use(conf.key,
|
2018-07-08 15:16:45 +00:00
|
|
|
new CASStrategy({
|
2022-07-16 23:41:41 +00:00
|
|
|
version: conf.casVersion,
|
|
|
|
ssoBaseURL: conf.casUrl,
|
|
|
|
serverBaseURL: conf.baseUrl,
|
|
|
|
serviceURL: conf.callbackURL,
|
2020-08-30 05:36:17 +00:00
|
|
|
passReqToCallback: true
|
|
|
|
}, async (req, profile, cb) => {
|
|
|
|
try {
|
|
|
|
const user = await WIKI.models.users.processProfile({
|
|
|
|
providerKey: req.params.strategy,
|
2022-07-16 23:41:41 +00:00
|
|
|
profile: {
|
|
|
|
...profile,
|
|
|
|
id: _.get(profile.attributes, conf.uniqueIdAttribute, profile.user),
|
|
|
|
email: _.get(profile.attributes, conf.emailAttribute),
|
|
|
|
name: _.get(profile.attributes, conf.displayNameAttribute, profile.user),
|
|
|
|
picture: ''
|
|
|
|
}
|
2020-08-30 05:36:17 +00:00
|
|
|
})
|
2022-07-16 23:41:41 +00:00
|
|
|
|
2020-08-30 05:36:17 +00:00
|
|
|
cb(null, user)
|
|
|
|
} catch (err) {
|
|
|
|
cb(err, null)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
2018-07-08 15:16:45 +00:00
|
|
|
}
|
|
|
|
}
|