authentication.js 962 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* global WIKI */
  2. // ------------------------------------
  3. // Okta Account
  4. // ------------------------------------
  5. const OktaStrategy = require('passport-okta-oauth').Strategy
  6. const _ = require('lodash')
  7. module.exports = {
  8. init (passport, conf) {
  9. passport.use('okta',
  10. new OktaStrategy({
  11. audience: conf.audience,
  12. clientID: conf.clientId,
  13. clientSecret: conf.clientSecret,
  14. idp: conf.idp,
  15. callbackURL: conf.callbackURL,
  16. response_type: 'code',
  17. passReqToCallback: true
  18. }, async (req, accessToken, refreshToken, profile, cb) => {
  19. try {
  20. const user = await WIKI.models.users.processProfile({
  21. providerKey: req.params.strategy,
  22. profile: {
  23. ...profile,
  24. picture: _.get(profile, '_json.profile', '')
  25. }
  26. })
  27. cb(null, user)
  28. } catch (err) {
  29. cb(err, null)
  30. }
  31. })
  32. )
  33. }
  34. }