authentication.js 964 Bytes
Newer Older
1 2 3 4 5 6 7
/* global WIKI */

// ------------------------------------
// Okta Account
// ------------------------------------

const OktaStrategy = require('passport-okta-oauth').Strategy
Nick's avatar
Nick committed
8
const _ = require('lodash')
9 10 11

module.exports = {
  init (passport, conf) {
12
    passport.use(conf.key,
13 14 15 16 17 18
      new OktaStrategy({
        audience: conf.audience,
        clientID: conf.clientId,
        clientSecret: conf.clientSecret,
        idp: conf.idp,
        callbackURL: conf.callbackURL,
19 20 21
        response_type: 'code',
        passReqToCallback: true
      }, async (req, accessToken, refreshToken, profile, cb) => {
Nick's avatar
Nick committed
22 23
        try {
          const user = await WIKI.models.users.processProfile({
24
            providerKey: req.params.strategy,
Nick's avatar
Nick committed
25 26 27
            profile: {
              ...profile,
              picture: _.get(profile, '_json.profile', '')
28
            }
Nick's avatar
Nick committed
29 30 31 32 33
          })
          cb(null, user)
        } catch (err) {
          cb(err, null)
        }
34 35 36 37
      })
    )
  }
}