Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

mod_token_verification.lua 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. -- Token authentication
  2. -- Copyright (C) 2015 Atlassian
  3. local log = module._log;
  4. local host = module.host;
  5. local st = require "util.stanza";
  6. local token_util = module:require("token/util");
  7. local is_admin = require "core.usermanager".is_admin;
  8. local parentHostName = string.gmatch(tostring(host), "%w+.(%w.+)")();
  9. if parentHostName == nil then
  10. log("error", "Failed to start - unable to get parent hostname");
  11. return;
  12. end
  13. local parentCtx = module:context(parentHostName);
  14. if parentCtx == nil then
  15. log("error", "Failed to start - unable to get parent context for host: %s", tostring(parentHostName));
  16. return;
  17. end
  18. local appId = parentCtx:get_option_string("app_id");
  19. local appSecret = parentCtx:get_option_string("app_secret");
  20. local tokenLifetime = parentCtx:get_option_string("token_lifetime");
  21. log("debug", "%s - starting MUC token verifier app_id: %s app_secret: %s token-lifetime: %s",
  22. tostring(host), tostring(appId), tostring(appSecret), tostring(tokenLifetime));
  23. local function handle_pre_create(event)
  24. local origin, stanza = event.origin, event.stanza;
  25. local token = stanza:get_child("token", "http://jitsi.org/jitmeet/auth-token");
  26. -- token not required for admin users
  27. local user_jid = stanza.attr.from;
  28. if is_admin(user_jid) then
  29. log("debug", "Token not required from admin user: %s", user_jid);
  30. return nil;
  31. end
  32. log("debug", "Will verify token for user: %s ", user_jid);
  33. if token ~= nil then
  34. token = token[1];
  35. end
  36. local result, msg = token_util.verify_password(token, appId, appSecret, tokenLifetime);
  37. if result ~= true then
  38. log("debug", "Token verification failed: %s", msg);
  39. origin.send(st.error_reply(stanza, "cancel", "not-allowed", msg));
  40. return true;
  41. end
  42. end
  43. module:hook("muc-room-pre-create", handle_pre_create);