2018-03-05 20:49:36 +00:00
|
|
|
/* global WIKI */
|
2017-07-29 21:33:08 +00:00
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Microsoft Account
|
|
|
|
// ------------------------------------
|
|
|
|
|
2019-04-27 03:59:35 +00:00
|
|
|
const WindowsLiveStrategy = require('passport-microsoft').Strategy
|
|
|
|
const _ = require('lodash')
|
2017-07-29 21:33:08 +00:00
|
|
|
|
2017-09-11 03:00:03 +00:00
|
|
|
module.exports = {
|
|
|
|
init (passport, conf) {
|
2017-10-01 03:47:14 +00:00
|
|
|
passport.use('microsoft',
|
2017-09-11 03:00:03 +00:00
|
|
|
new WindowsLiveStrategy({
|
|
|
|
clientID: conf.clientId,
|
|
|
|
clientSecret: conf.clientSecret,
|
2019-04-27 03:59:35 +00:00
|
|
|
callbackURL: conf.callbackURL,
|
2020-08-30 05:36:17 +00:00
|
|
|
scope: ['User.Read', 'email', 'openid', 'profile'],
|
|
|
|
passReqToCallback: true
|
|
|
|
}, async (req, accessToken, refreshToken, profile, cb) => {
|
2019-04-22 01:43:33 +00:00
|
|
|
try {
|
|
|
|
const user = await WIKI.models.users.processProfile({
|
2020-08-30 05:36:17 +00:00
|
|
|
providerKey: req.params.strategy,
|
2019-04-22 01:43:33 +00:00
|
|
|
profile: {
|
|
|
|
...profile,
|
|
|
|
picture: _.get(profile, 'photos[0].value', '')
|
2020-08-30 05:36:17 +00:00
|
|
|
}
|
2019-04-22 01:43:33 +00:00
|
|
|
})
|
|
|
|
cb(null, user)
|
|
|
|
} catch (err) {
|
|
|
|
cb(err, null)
|
|
|
|
}
|
2017-09-11 03:00:03 +00:00
|
|
|
}
|
|
|
|
))
|
|
|
|
}
|
2017-07-29 21:33:08 +00:00
|
|
|
}
|