You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

  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. let displayName = profile.username
  21. if (_.isString(profile.fullName) && profile.fullName.length > 0) {
  22. displayName = profile.fullName
  23. }
  24. try {
  25. const user = await WIKI.models.users.processProfile({
  26. profile: {
  27. id: profile.keycloakId,
  28. email: profile.email,
  29. name: displayName,
  30. picture: ''
  31. },
  32. providerKey: 'keycloak'
  33. })
  34. cb(null, user)
  35. } catch (err) {
  36. cb(err, null)
  37. }
  38. })
  39. )
  40. }
  41. }