authentication.js 962 Bytes
Newer Older
1
/* global WIKI */
2 3 4 5 6

// ------------------------------------
// Microsoft Account
// ------------------------------------

7 8
const WindowsLiveStrategy = require('passport-microsoft').Strategy
const _ = require('lodash')
9

10 11
module.exports = {
  init (passport, conf) {
12
    passport.use('microsoft',
13 14 15
      new WindowsLiveStrategy({
        clientID: conf.clientId,
        clientSecret: conf.clientSecret,
16
        callbackURL: conf.callbackURL,
17 18 19
        scope: ['User.Read', 'email', 'openid', 'profile'],
        passReqToCallback: true
      }, async (req, accessToken, refreshToken, profile, cb) => {
20 21
        try {
          const user = await WIKI.models.users.processProfile({
22
            providerKey: req.params.strategy,
23 24 25
            profile: {
              ...profile,
              picture: _.get(profile, 'photos[0].value', '')
26
            }
27 28 29 30 31
          })
          cb(null, user)
        } catch (err) {
          cb(err, null)
        }
32 33 34
      }
      ))
  }
35
}