authentication.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. try {
  20. const user = await WIKI.models.users.processProfile({
  21. profile: {
  22. id: profile.oid,
  23. displayName: profile.displayName,
  24. email: _.get(profile, '_json.email', ''),
  25. picture: ''
  26. },
  27. providerKey: 'azure'
  28. })
  29. cb(null, user)
  30. } catch (err) {
  31. cb(err, null)
  32. }
  33. })
  34. )
  35. }
  36. }