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

41 lines
1.0 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
2019-07-20 15:09:55 +00:00
}, async (iss, sub, profile, cb) => {
try {
const user = await WIKI.models.users.processProfile({
profile: {
id: profile.oid,
displayName: profile.displayName,
email: _.get(profile, '_json.email', ''),
picture: ''
},
providerKey: 'azure'
})
cb(null, user)
} catch (err) {
cb(err, null)
}
})
)
}
2017-07-29 21:33:08 +00:00
}