選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

mod_auth_token.lua 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. -- Token authentication
  2. -- Copyright (C) 2015 Atlassian
  3. local generate_uuid = require "util.uuid".generate;
  4. local new_sasl = require "util.sasl".new;
  5. local sasl = require "util.sasl";
  6. local formdecode = require "util.http".formdecode;
  7. local token_util = module:require "token/util";
  8. -- define auth provider
  9. local provider = {};
  10. local host = module.host;
  11. local appId = module:get_option_string("app_id");
  12. local appSecret = module:get_option_string("app_secret");
  13. local allowEmptyToken = module:get_option_boolean("allow_empty_token");
  14. if allowEmptyToken == true then
  15. module:log("warn", "WARNING - empty tokens allowed");
  16. end
  17. if appId == nil then
  18. module:log("error", "'app_id' must not be empty");
  19. return;
  20. end
  21. if appSecret == nil then
  22. module:log("error", "'app_secret' must not be empty");
  23. return;
  24. end
  25. -- Extract 'token' param from BOSH URL when session is created
  26. module:hook("bosh-session", function(event)
  27. local session, request = event.session, event.request;
  28. local query = request.url.query;
  29. if query ~= nil then
  30. session.auth_token = query and formdecode(query).token or nil;
  31. end
  32. end)
  33. function provider.test_password(username, password)
  34. return nil, "Password based auth not supported";
  35. end
  36. function provider.get_password(username)
  37. return nil;
  38. end
  39. function provider.set_password(username, password)
  40. return nil, "Set password not supported";
  41. end
  42. function provider.user_exists(username)
  43. return nil;
  44. end
  45. function provider.create_user(username, password)
  46. return nil;
  47. end
  48. function provider.delete_user(username)
  49. return nil;
  50. end
  51. function provider.get_sasl_handler(session)
  52. -- JWT token extracted from BOSH URL
  53. local token = session.auth_token;
  54. local function get_username_from_token(self, message)
  55. if token == nil then
  56. if allowEmptyToken == true then
  57. return true;
  58. else
  59. return false, "not-allowed", "token required";
  60. end
  61. end
  62. -- here we check if 'room' claim exists
  63. local room, roomErr = token_util.get_room_name(token, appSecret);
  64. if room == nil then
  65. return false, "not-allowed", roomErr;
  66. end
  67. -- now verify the whole token
  68. local result, msg
  69. = token_util.verify_token(token, appId, appSecret, room);
  70. if result == true then
  71. -- Binds room name to the session which is later checked on MUC join
  72. session.jitsi_meet_room = room;
  73. return true
  74. else
  75. return false, "not-allowed", msg
  76. end
  77. end
  78. return new_sasl(host, { anonymous = get_username_from_token });
  79. end
  80. module:provides("auth", provider);
  81. local function anonymous(self, message)
  82. local username = generate_uuid();
  83. -- This calls the handler created in 'provider.get_sasl_handler(session)'
  84. local result, err, msg = self.profile.anonymous(self, username, self.realm);
  85. self.username = username;
  86. if result == true then
  87. return "success"
  88. else
  89. return "failure", err, msg
  90. end
  91. end
  92. sasl.registerMechanism("ANONYMOUS", {"anonymous"}, anonymous);