2018-03-05 20:49:36 +00:00
|
|
|
/* global WIKI */
|
2017-07-29 21:33:08 +00:00
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Azure AD Account
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
const AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2').Strategy
|
|
|
|
|
2017-09-11 03:00:03 +00:00
|
|
|
module.exports = {
|
|
|
|
key: 'azure',
|
|
|
|
title: 'Azure Active Directory',
|
2017-09-25 03:22:33 +00:00
|
|
|
useForm: false,
|
2017-12-31 19:40:28 +00:00
|
|
|
props: ['clientId', 'clientSecret', 'resource', 'tenant'],
|
2017-09-11 03:00:03 +00:00
|
|
|
init (passport, conf) {
|
|
|
|
const jwt = require('jsonwebtoken')
|
|
|
|
passport.use('azure_ad_oauth2',
|
|
|
|
new AzureAdOAuth2Strategy({
|
|
|
|
clientID: conf.clientId,
|
|
|
|
clientSecret: conf.clientSecret,
|
|
|
|
callbackURL: conf.callbackURL,
|
|
|
|
resource: conf.resource,
|
|
|
|
tenant: conf.tenant
|
|
|
|
}, (accessToken, refreshToken, params, profile, cb) => {
|
|
|
|
let waadProfile = jwt.decode(params.id_token)
|
|
|
|
waadProfile.id = waadProfile.oid
|
|
|
|
waadProfile.provider = 'azure'
|
2018-03-05 20:49:36 +00:00
|
|
|
WIKI.db.User.processProfile(waadProfile).then((user) => {
|
2017-09-11 03:00:03 +00:00
|
|
|
return cb(null, user) || true
|
|
|
|
}).catch((err) => {
|
|
|
|
return cb(err, null) || true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
))
|
|
|
|
}
|
2017-07-29 21:33:08 +00:00
|
|
|
}
|