authentication.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const _ = require('lodash')
  2. /* global WIKI */
  3. // ------------------------------------
  4. // Keycloak Account
  5. // ------------------------------------
  6. const KeycloakStrategy = require('@exlinc/keycloak-passport')
  7. module.exports = {
  8. init (passport, conf) {
  9. passport.use('keycloak',
  10. new KeycloakStrategy({
  11. authorizationURL: conf.authorizationURL,
  12. userInfoURL: conf.userInfoURL,
  13. tokenURL: conf.tokenURL,
  14. host: conf.host,
  15. realm: conf.realm,
  16. clientID: conf.clientId,
  17. clientSecret: conf.clientSecret,
  18. callbackURL: conf.callbackURL
  19. }, async (accessToken, refreshToken, profile, cb) => {
  20. try {
  21. const user = await WIKI.models.users.processProfile({
  22. profile: {
  23. id: profile.keycloakId,
  24. email: profile.email,
  25. name: profile.username,
  26. picture: ''
  27. },
  28. providerKey: 'keycloak'
  29. })
  30. cb(null, user)
  31. } catch (err) {
  32. cb(err, null)
  33. }
  34. })
  35. )
  36. }
  37. }