changeset 4322:9606e7a63a69

mod_mucc_http_auth: Provide Authorization header setting for deployments behind a login
author Seve Ferrer <seve@delape.net>
date Wed, 06 Jan 2021 20:49:45 +0100
parents 71498f484c22
children a7a06c8cea37
files mod_muc_http_auth/README.md mod_muc_http_auth/mod_muc_http_auth.lua
diffstat 2 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_http_auth/README.md	Wed Jan 06 17:07:16 2021 +0100
+++ b/mod_muc_http_auth/README.md	Wed Jan 06 20:49:45 2021 +0100
@@ -45,6 +45,7 @@
 |muc_http_auth_enabled_for| List of MUC names (node part) to enable this module for | nil |
 |muc_http_auth_disabled_for| List of MUC names (node part) to disable this module for | nil |
 |muc_http_auth_insecure| Disable certificate verification for request. Only intended for development of the external service. | false |
+|muc_http_auth_authorization_header| Value of the Authorization header if requested by the external HTTP service. Example: `Basic dXNlcm5hbWU6cGFzc3dvcmQ=`| nil |
 
 
 This module can be enabled/disabled for specific rooms. Only one of the following settings must be set.
--- a/mod_muc_http_auth/mod_muc_http_auth.lua	Wed Jan 06 17:07:16 2021 +0100
+++ b/mod_muc_http_auth/mod_muc_http_auth.lua	Wed Jan 06 20:49:45 2021 +0100
@@ -10,6 +10,12 @@
 local disabled_for = module:get_option_set("muc_http_auth_disabled_for",  nil)
 local insecure = module:get_option("muc_http_auth_insecure", false) --For development purposes
 local authorize_registration = module:get_option("muc_http_auth_authorize_registration", false)
+local authorization_header = module:get_option("muc_http_auth_authorization_header", nil)
+
+local options = {method="GET", insecure=insecure}
+if authorization_header then
+	options.headers = {["Authorization"] = authorization_header};
+end
 
 local verbs = {presence='join', iq='register'};
 
@@ -47,7 +53,7 @@
 	local user_bare_jid = jid_bare(stanza.attr.from);
 	local url = authorization_url .. "?userJID=" .. user_bare_jid .."&mucJID=" .. room.jid;
 
-	local result = wait_for(http.request(url, {method="GET", insecure=insecure}):next(handle_success, handle_error));
+	local result = wait_for(http.request(url, options):next(handle_success, handle_error));
 	local response, err = result.response, result.err;
 
 	local verb = verbs[stanza.name];