wikijs-fork/server/modules/authentication/azure/authentication.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-07-20 15:09:55 +00:00
const _ = require('lodash')
/* 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
module.exports = {
init (passport, conf) {
2019-07-20 04:16:29 +00:00
passport.use('azure',
new OIDCStrategy({
identityMetadata: conf.entryPoint,
clientID: conf.clientId,
2019-07-20 04:16:29 +00:00
redirectUrl: conf.callbackURL,
responseType: 'id_token',
responseMode: 'form_post',
scope: ['profile', 'email', 'openid'],
allowHttpForRedirectUrl: WIKI.IS_DEBUG,
passReqToCallback: true
}, async (req, iss, sub, profile, cb) => {
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({
providerKey: req.params.strategy,
2019-07-20 15:09:55 +00:00
profile: {
id: profile.oid,
displayName: profile.displayName,
email: usrEmail,
2019-07-20 15:09:55 +00:00
picture: ''
}
2019-07-20 15:09:55 +00:00
})
cb(null, user)
} catch (err) {
cb(err, null)
}
})
)
}
2017-07-29 21:33:08 +00:00
}