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_token.lua 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. -- Token authentication
  2. -- Copyright (C) 2015 Atlassian
  3. local formdecode = require "util.http".formdecode;
  4. local generate_uuid = require "util.uuid".generate;
  5. local new_sasl = require "util.sasl".new;
  6. local sasl = require "util.sasl";
  7. local token_util = module:require "token/util".new(module);
  8. -- no token configuration
  9. if token_util == nil then
  10. return;
  11. end
  12. -- define auth provider
  13. local provider = {};
  14. local host = module.host;
  15. -- Extract 'token' param from BOSH URL when session is created
  16. module:hook("bosh-session", function(event)
  17. local session, request = event.session, event.request;
  18. local query = request.url.query;
  19. if query ~= nil then
  20. local params = formdecode(query);
  21. session.auth_token = query and params.token or nil;
  22. -- The room name from the bosh query
  23. session.jitsi_bosh_query_room = params.room;
  24. end
  25. end);
  26. function provider.test_password(username, password)
  27. return nil, "Password based auth not supported";
  28. end
  29. function provider.get_password(username)
  30. return nil;
  31. end
  32. function provider.set_password(username, password)
  33. return nil, "Set password not supported";
  34. end
  35. function provider.user_exists(username)
  36. return nil;
  37. end
  38. function provider.create_user(username, password)
  39. return nil;
  40. end
  41. function provider.delete_user(username)
  42. return nil;
  43. end
  44. function provider.get_sasl_handler(session)
  45. local function get_username_from_token(self, message)
  46. local res, error, reason = token_util:process_and_verify_token(session);
  47. if (res == false) then
  48. log("warn",
  49. "Error verifying token err:%s, reason:%s", error, reason);
  50. end
  51. local customUsername
  52. = prosody.events.fire_event("pre-jitsi-authentication", session);
  53. if (customUsername) then
  54. self.username = customUsername;
  55. else
  56. self.username = message;
  57. end
  58. return res;
  59. end
  60. return new_sasl(host, { anonymous = get_username_from_token });
  61. end
  62. module:provides("auth", provider);
  63. local function anonymous(self, message)
  64. local username = generate_uuid();
  65. -- This calls the handler created in 'provider.get_sasl_handler(session)'
  66. local result, err, msg = self.profile.anonymous(self, username, self.realm);
  67. if result == true then
  68. return "success";
  69. else
  70. return "failure", err, msg;
  71. end
  72. end
  73. sasl.registerMechanism("ANONYMOUS", {"anonymous"}, anonymous);