authentication.js 993 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. const _ = require('lodash')
  2. /* global WIKI */
  3. // ------------------------------------
  4. // OpenID Connect Account
  5. // ------------------------------------
  6. const OpenIDConnectStrategy = require('passport-openidconnect').Strategy
  7. module.exports = {
  8. init (passport, conf) {
  9. passport.use('oidc',
  10. new OpenIDConnectStrategy({
  11. authorizationURL: conf.authorizationURL,
  12. tokenURL: conf.tokenURL,
  13. clientID: conf.clientId,
  14. clientSecret: conf.clientSecret,
  15. issuer: conf.issuer,
  16. userInfoURL: conf.userInfoURL,
  17. callbackURL: conf.callbackURL
  18. }, async (iss, sub, profile, cb) => {
  19. try {
  20. const user = await WIKI.models.users.processProfile({
  21. profile: {
  22. ...profile,
  23. email: _.get(profile, '_json.' + conf.emailClaim)
  24. },
  25. providerKey: 'oidc'
  26. })
  27. cb(null, user)
  28. } catch(err) {
  29. cb(err, null)
  30. }
  31. })
  32. )
  33. }
  34. }