Diff

mod_muc_http_auth/mod_muc_http_auth.lua @ 4695:4b3f054666e6

mod_muc_http_auth: External auth services might need to check on the nickname as well
author Seve Ferrer <seve@delape.net>
date Tue, 21 Sep 2021 14:00:01 +0200
parent 4322:9606e7a63a69
child 4696:6a05c9eb964e
line wrap: on
line diff
--- a/mod_muc_http_auth/mod_muc_http_auth.lua	Sat Sep 18 11:51:48 2021 +0100
+++ b/mod_muc_http_auth/mod_muc_http_auth.lua	Tue Sep 21 14:00:01 2021 +0200
@@ -4,6 +4,7 @@
 local st = require "util.stanza";
 local jid_node = require "util.jid".node;
 local jid_bare = require "util.jid".bare;
+local jid_resource = require "util.jid".resource;
 
 local authorization_url = module:get_option("muc_http_auth_url", "")
 local enabled_for = module:get_option_set("muc_http_auth_enabled_for",  nil)
@@ -51,7 +52,12 @@
 	if not must_be_authorized(jid_node(room.jid)) then return; end
 
 	local user_bare_jid = jid_bare(stanza.attr.from);
-	local url = authorization_url .. "?userJID=" .. user_bare_jid .."&mucJID=" .. room.jid;
+	local user_nickname = jid_resource(stanza.attr.to);
+
+	-- Nickname is mandatory to enter a MUC
+	if not user_nickname then return; end
+
+	local url = authorization_url .. "?userJID=" .. user_bare_jid .."&mucJID=" .. room.jid .. "&nickname=" .. user_nickname;
 
 	local result = wait_for(http.request(url, options):next(handle_success, handle_error));
 	local response, err = result.response, result.err;