authentication.js 946 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 17
        callbackURL: conf.callbackURL,
        scope: ['User.Read', 'email', 'openid', 'profile']
18 19 20 21 22 23 24 25 26 27 28 29 30 31
      }, 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)
        }
32 33 34
      }
      ))
  }
35
}