authentication.js 987 B

1234567891011121314151617181920212223242526272829303132
  1. /* global WIKI */
  2. // ------------------------------------
  3. // Azure AD Account
  4. // ------------------------------------
  5. const AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2').Strategy
  6. module.exports = {
  7. init (passport, conf) {
  8. const jwt = require('jsonwebtoken')
  9. passport.use('azure_ad_oauth2',
  10. new AzureAdOAuth2Strategy({
  11. clientID: conf.clientId,
  12. clientSecret: conf.clientSecret,
  13. callbackURL: conf.callbackURL,
  14. resource: conf.resource,
  15. tenant: conf.tenant
  16. }, (accessToken, refreshToken, params, profile, cb) => {
  17. console.info(params, profile)
  18. let waadProfile = jwt.decode(params.id_token)
  19. waadProfile.id = waadProfile.oid
  20. waadProfile.provider = 'azure'
  21. // WIKI.models.users.processProfile(waadProfile).then((user) => {
  22. // return cb(null, user) || true
  23. // }).catch((err) => {
  24. // return cb(err, null) || true
  25. // })
  26. }
  27. ))
  28. }
  29. }