authentication.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const _ = require('lodash')
  2. // ------------------------------------
  3. // OpenID Connect Account
  4. // ------------------------------------
  5. const OpenIDConnectStrategy = require('passport-openidconnect').Strategy
  6. module.exports = {
  7. init (passport, conf) {
  8. passport.use(conf.key,
  9. new OpenIDConnectStrategy({
  10. authorizationURL: conf.authorizationURL,
  11. tokenURL: conf.tokenURL,
  12. clientID: conf.clientId,
  13. clientSecret: conf.clientSecret,
  14. issuer: conf.issuer,
  15. userInfoURL: conf.userInfoURL,
  16. callbackURL: conf.callbackURL,
  17. passReqToCallback: true
  18. }, async (req, iss, sub, profile, cb) => {
  19. try {
  20. const user = await WIKI.db.users.processProfile({
  21. providerKey: req.params.strategy,
  22. profile: {
  23. ...profile,
  24. email: _.get(profile, '_json.' + conf.emailClaim)
  25. }
  26. })
  27. cb(null, user)
  28. } catch (err) {
  29. cb(err, null)
  30. }
  31. })
  32. )
  33. },
  34. logout (conf) {
  35. if (!conf.logoutURL) {
  36. return '/'
  37. } else {
  38. return conf.logoutURL
  39. }
  40. }
  41. }