mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
36 lines
1.0 KiB
8 years ago
|
/* global wiki */
|
||
|
|
||
|
// ------------------------------------
|
||
|
// Azure AD Account
|
||
|
// ------------------------------------
|
||
|
|
||
|
const AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2').Strategy
|
||
|
|
||
7 years ago
|
module.exports = {
|
||
|
key: 'azure',
|
||
|
title: 'Azure Active Directory',
|
||
7 years ago
|
useForm: false,
|
||
7 years ago
|
props: ['clientId', 'clientSecret', 'resource', 'tenant'],
|
||
7 years ago
|
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'
|
||
|
wiki.db.User.processProfile(waadProfile).then((user) => {
|
||
|
return cb(null, user) || true
|
||
|
}).catch((err) => {
|
||
|
return cb(err, null) || true
|
||
|
})
|
||
|
}
|
||
|
))
|
||
|
}
|
||
8 years ago
|
}
|