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.

37 lines
1.1 KiB

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