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.

31 lines
934 B

  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. let waadProfile = jwt.decode(params.id_token)
  18. waadProfile.id = waadProfile.oid
  19. waadProfile.provider = 'azure'
  20. WIKI.models.users.processProfile(waadProfile).then((user) => {
  21. return cb(null, user) || true
  22. }).catch((err) => {
  23. return cb(err, null) || true
  24. })
  25. }
  26. ))
  27. }
  28. }