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.

35 lines
1.0 KiB

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