comparison 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
parents 9606e7a63a69
children 6a05c9eb964e
comparison
equal deleted inserted replaced
4694:6c57b9e31586 4695:4b3f054666e6
2 local http = require "net.http"; 2 local http = require "net.http";
3 local json = require "util.json"; 3 local json = require "util.json";
4 local st = require "util.stanza"; 4 local st = require "util.stanza";
5 local jid_node = require "util.jid".node; 5 local jid_node = require "util.jid".node;
6 local jid_bare = require "util.jid".bare; 6 local jid_bare = require "util.jid".bare;
7 local jid_resource = require "util.jid".resource;
7 8
8 local authorization_url = module:get_option("muc_http_auth_url", "") 9 local authorization_url = module:get_option("muc_http_auth_url", "")
9 local enabled_for = module:get_option_set("muc_http_auth_enabled_for", nil) 10 local enabled_for = module:get_option_set("muc_http_auth_enabled_for", nil)
10 local disabled_for = module:get_option_set("muc_http_auth_disabled_for", nil) 11 local disabled_for = module:get_option_set("muc_http_auth_disabled_for", nil)
11 local insecure = module:get_option("muc_http_auth_insecure", false) --For development purposes 12 local insecure = module:get_option("muc_http_auth_insecure", false) --For development purposes
49 if (not room) or (not origin) then return; end 50 if (not room) or (not origin) then return; end
50 51
51 if not must_be_authorized(jid_node(room.jid)) then return; end 52 if not must_be_authorized(jid_node(room.jid)) then return; end
52 53
53 local user_bare_jid = jid_bare(stanza.attr.from); 54 local user_bare_jid = jid_bare(stanza.attr.from);
54 local url = authorization_url .. "?userJID=" .. user_bare_jid .."&mucJID=" .. room.jid; 55 local user_nickname = jid_resource(stanza.attr.to);
56
57 -- Nickname is mandatory to enter a MUC
58 if not user_nickname then return; end
59
60 local url = authorization_url .. "?userJID=" .. user_bare_jid .."&mucJID=" .. room.jid .. "&nickname=" .. user_nickname;
55 61
56 local result = wait_for(http.request(url, options):next(handle_success, handle_error)); 62 local result = wait_for(http.request(url, options):next(handle_success, handle_error));
57 local response, err = result.response, result.err; 63 local response, err = result.response, result.err;
58 64
59 local verb = verbs[stanza.name]; 65 local verb = verbs[stanza.name];