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