您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

mod_token_verification.lua 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. log("debug", "%s - starting MUC token verifier app_id: %s app_secret: %s",
  21. tostring(host), tostring(appId), tostring(appSecret));
  22. local function handle_pre_create(event)
  23. local origin, stanza = event.origin, event.stanza;
  24. local token = stanza:get_child("token", "http://jitsi.org/jitmeet/auth-token");
  25. -- token not required for admin users
  26. local user_jid = stanza.attr.from;
  27. if is_admin(user_jid) then
  28. log("debug", "Token not required from admin user: %s", user_jid);
  29. return nil;
  30. end
  31. local room = string.match(stanza.attr.to, "^(%w+)@");
  32. log("debug", "Will verify token for user: %s, room: %s ", user_jid, room);
  33. if room == nil then
  34. log("error", "Unable to get name of the MUC room ? to: %s", stanza.attr.to);
  35. return nil;
  36. end
  37. if token ~= nil then
  38. token = token[1];
  39. end
  40. local result, msg = token_util.verify_password(token, appId, appSecret, room);
  41. if result ~= true then
  42. log("debug", "Token verification failed: %s", msg);
  43. origin.send(st.error_reply(stanza, "cancel", "not-allowed", msg));
  44. return true;
  45. end
  46. end
  47. module:hook("muc-room-pre-create", handle_pre_create);