|
|
|
@ -8,26 +8,24 @@
|
|
|
|
|
|
|
|
|
|
const AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2').Strategy
|
|
|
|
|
|
|
|
|
|
module.exports = (passport) => {
|
|
|
|
|
if (wiki.config.auth.azure && wiki.config.auth.azure.enabled) {
|
|
|
|
|
const jwt = require('jsonwebtoken')
|
|
|
|
|
passport.use('azure_ad_oauth2',
|
|
|
|
|
new AzureAdOAuth2Strategy({
|
|
|
|
|
clientID: wiki.config.auth.azure.clientId,
|
|
|
|
|
clientSecret: wiki.config.auth.azure.clientSecret,
|
|
|
|
|
callbackURL: wiki.config.host + '/login/azure/callback',
|
|
|
|
|
resource: wiki.config.auth.azure.resource,
|
|
|
|
|
tenant: wiki.config.auth.azure.tenant
|
|
|
|
|
}, (accessToken, refreshToken, params, profile, cb) => {
|
|
|
|
|
let waadProfile = jwt.decode(params.id_token)
|
|
|
|
|
waadProfile.id = waadProfile.oid
|
|
|
|
|
waadProfile.provider = 'azure'
|
|
|
|
|
wiki.db.User.processProfile(waadProfile).then((user) => {
|
|
|
|
|
return cb(null, user) || true
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
return cb(err, null) || true
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
module.exports = (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'
|
|
|
|
|
wiki.db.User.processProfile(waadProfile).then((user) => {
|
|
|
|
|
return cb(null, user) || true
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
return cb(err, null) || true
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|