2019-07-20 15:09:55 +00:00
|
|
|
const _ = require('lodash')
|
|
|
|
|
2018-03-05 20:49:36 +00:00
|
|
|
/* global WIKI */
|
2017-07-29 21:33:08 +00:00
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Azure AD Account
|
|
|
|
// ------------------------------------
|
|
|
|
|
2019-07-20 04:16:29 +00:00
|
|
|
const OIDCStrategy = require('passport-azure-ad').OIDCStrategy
|
2017-07-29 21:33:08 +00:00
|
|
|
|
2017-09-11 03:00:03 +00:00
|
|
|
module.exports = {
|
|
|
|
init (passport, conf) {
|
2019-07-20 04:16:29 +00:00
|
|
|
passport.use('azure',
|
|
|
|
new OIDCStrategy({
|
|
|
|
identityMetadata: conf.entryPoint,
|
2017-09-11 03:00:03 +00:00
|
|
|
clientID: conf.clientId,
|
2019-07-20 04:16:29 +00:00
|
|
|
redirectUrl: conf.callbackURL,
|
|
|
|
responseType: 'id_token',
|
|
|
|
responseMode: 'form_post',
|
|
|
|
scope: ['profile', 'email', 'openid'],
|
2020-08-30 05:36:17 +00:00
|
|
|
allowHttpForRedirectUrl: WIKI.IS_DEBUG,
|
|
|
|
passReqToCallback: true
|
|
|
|
}, async (req, iss, sub, profile, cb) => {
|
2019-10-27 17:57:39 +00:00
|
|
|
const usrEmail = _.get(profile, '_json.email', null) || _.get(profile, '_json.preferred_username')
|
2019-07-20 15:09:55 +00:00
|
|
|
try {
|
|
|
|
const user = await WIKI.models.users.processProfile({
|
2020-08-30 05:36:17 +00:00
|
|
|
providerKey: req.params.strategy,
|
2019-07-20 15:09:55 +00:00
|
|
|
profile: {
|
|
|
|
id: profile.oid,
|
|
|
|
displayName: profile.displayName,
|
2019-10-27 17:57:39 +00:00
|
|
|
email: usrEmail,
|
2019-07-20 15:09:55 +00:00
|
|
|
picture: ''
|
2020-08-30 05:36:17 +00:00
|
|
|
}
|
2019-07-20 15:09:55 +00:00
|
|
|
})
|
|
|
|
cb(null, user)
|
|
|
|
} catch (err) {
|
|
|
|
cb(err, null)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
2017-09-11 03:00:03 +00:00
|
|
|
}
|
2017-07-29 21:33:08 +00:00
|
|
|
}
|