authentication.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const _ = require('lodash')
  2. /* global WIKI */
  3. // ------------------------------------
  4. // Azure AD Account
  5. // ------------------------------------
  6. const OIDCStrategy = require('passport-azure-ad').OIDCStrategy
  7. module.exports = {
  8. init (passport, conf) {
  9. passport.use('azure',
  10. new OIDCStrategy({
  11. identityMetadata: conf.entryPoint,
  12. clientID: conf.clientId,
  13. redirectUrl: conf.callbackURL,
  14. responseType: 'id_token',
  15. responseMode: 'form_post',
  16. scope: ['profile', 'email', 'openid'],
  17. allowHttpForRedirectUrl: WIKI.IS_DEBUG
  18. }, async (iss, sub, profile, cb) => {
  19. const usrEmail = _.get(profile, '_json.email', null) || _.get(profile, '_json.preferred_username')
  20. try {
  21. const user = await WIKI.models.users.processProfile({
  22. profile: {
  23. id: profile.oid,
  24. displayName: profile.displayName,
  25. email: usrEmail,
  26. picture: ''
  27. },
  28. providerKey: 'azure'
  29. })
  30. cb(null, user)
  31. } catch (err) {
  32. cb(err, null)
  33. }
  34. })
  35. )
  36. }
  37. }