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.

mod_auth_jitsi-annonymous.lua 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. -- Anonymous authentication with extras:
  2. -- * session resumption
  3. -- Copyright (C) 2021-present 8x8, Inc.
  4. local new_sasl = require "util.sasl".new;
  5. local sasl = require "util.sasl";
  6. local sessions = prosody.full_sessions;
  7. -- define auth provider
  8. local provider = {};
  9. function provider.test_password(username, password)
  10. return nil, "Password based auth not supported";
  11. end
  12. function provider.get_password(username)
  13. return nil;
  14. end
  15. function provider.set_password(username, password)
  16. return nil, "Set password not supported";
  17. end
  18. function provider.user_exists(username)
  19. return nil;
  20. end
  21. function provider.create_user(username, password)
  22. return nil;
  23. end
  24. function provider.delete_user(username)
  25. return nil;
  26. end
  27. function provider.get_sasl_handler(session)
  28. -- Custom session matching so we can resume sesssion even with randomly
  29. -- generrated user IDs.
  30. local function get_username(self, message)
  31. if (session.previd ~= nil) then
  32. for _, session1 in pairs(sessions) do
  33. if (session1.resumption_token == session.previd) then
  34. self.username = session1.username;
  35. break;
  36. end
  37. end
  38. else
  39. self.username = message;
  40. end
  41. return true;
  42. end
  43. return new_sasl(module.host, { anonymous = get_username });
  44. end
  45. module:provides("auth", provider);
  46. local function anonymous(self, message)
  47. -- This calls the handler created in 'provider.get_sasl_handler(session)'
  48. local result, err, msg = self.profile.anonymous(self, username, self.realm);
  49. if result == true then
  50. return "success";
  51. else
  52. return "failure", err, msg;
  53. end
  54. end
  55. sasl.registerMechanism("ANONYMOUS", {"anonymous"}, anonymous);