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.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 = token_util:process_and_verify_token(session);
  47. local customUsername
  48. = prosody.events.fire_event("pre-jitsi-authentication", session);
  49. if (customUsername) then
  50. self.username = customUsername;
  51. else
  52. self.username = message;
  53. end
  54. return res;
  55. end
  56. return new_sasl(host, { anonymous = get_username_from_token });
  57. end
  58. module:provides("auth", provider);
  59. local function anonymous(self, message)
  60. local username = generate_uuid();
  61. -- This calls the handler created in 'provider.get_sasl_handler(session)'
  62. local result, err, msg = self.profile.anonymous(self, username, self.realm);
  63. if result == true then
  64. return "success";
  65. else
  66. return "failure", err, msg;
  67. end
  68. end
  69. sasl.registerMechanism("ANONYMOUS", {"anonymous"}, anonymous);