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.

35 lines
962 B

  1. /* global WIKI */
  2. // ------------------------------------
  3. // Microsoft Account
  4. // ------------------------------------
  5. const WindowsLiveStrategy = require('passport-microsoft').Strategy
  6. const _ = require('lodash')
  7. module.exports = {
  8. init (passport, conf) {
  9. passport.use('microsoft',
  10. new WindowsLiveStrategy({
  11. clientID: conf.clientId,
  12. clientSecret: conf.clientSecret,
  13. callbackURL: conf.callbackURL,
  14. scope: ['User.Read', 'email', 'openid', 'profile'],
  15. passReqToCallback: true
  16. }, async (req, accessToken, refreshToken, profile, cb) => {
  17. try {
  18. const user = await WIKI.models.users.processProfile({
  19. providerKey: req.params.strategy,
  20. profile: {
  21. ...profile,
  22. picture: _.get(profile, 'photos[0].value', '')
  23. }
  24. })
  25. cb(null, user)
  26. } catch (err) {
  27. cb(err, null)
  28. }
  29. }
  30. ))
  31. }
  32. }