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
895 B

  1. 'use strict'
  2. /* global wiki */
  3. // ------------------------------------
  4. // Azure AD Account
  5. // ------------------------------------
  6. const AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2').Strategy
  7. module.exports = (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.db.User.processProfile(waadProfile).then((user) => {
  21. return cb(null, user) || true
  22. }).catch((err) => {
  23. return cb(err, null) || true
  24. })
  25. }
  26. ))
  27. }