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,
|
2018-07-01 23:50:42 +00:00
|
|
|
props: {
|
|
|
|
clientId: String,
|
|
|
|
clientSecret: String,
|
|
|
|
resource: {
|
|
|
|
type: String,
|
|
|
|
default: '00000002-0000-0000-c000-000000000000'
|
|
|
|
},
|
|
|
|
tenant: {
|
|
|
|
type: String,
|
|
|
|
default: 'YOUR_TENANT.onmicrosoft.com'
|
|
|
|
}
|
|
|
|
},
|
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-05-19 20:40:07 +00:00
|
|
|
WIKI.db.users.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
|
|
|
}
|