diff mod_auth_http_async/mod_auth_http_async.lua @ 6318:07808fcda0e4

mod_auth_http_async: Remove non-async code (really should not be needed anymore)
author Kim Alvefur <zash@zash.se>
date Tue, 02 Sep 2025 22:19:51 +0200
parents 39156d6f7268
children
line wrap: on
line diff
--- a/mod_auth_http_async/mod_auth_http_async.lua	Tue Sep 02 21:32:01 2025 +0200
+++ b/mod_auth_http_async/mod_auth_http_async.lua	Tue Sep 02 22:19:51 2025 +0200
@@ -9,7 +9,7 @@
 
 local new_sasl = require "util.sasl".new;
 local base64 = require "util.encodings".base64.encode;
-local have_async, async = pcall(require, "util.async");
+local async = require "util.async";
 
 local log = module._log;
 local host = module.host;
@@ -19,22 +19,6 @@
 
 local provider = {};
 
--- globals required by socket.http
-if rawget(_G, "PROXY") == nil then
-	rawset(_G, "PROXY", false)
-end
-if rawget(_G, "base_parsed") == nil then
-	rawset(_G, "base_parsed", false)
-end
-if not have_async then -- FINE! Set your globals then
-	prosody.unlock_globals()
-	require "ltn12"
-	require "socket"
-	require "socket.http"
-	require "ssl.https"
-	prosody.lock_globals()
-end
-
 local function async_http_auth(url, username, password)
 	module:log("debug", "async_http_auth()");
 	local http = require "net.http";
@@ -58,38 +42,10 @@
 	return nil, "Auth failed. Invalid username or password.";
 end
 
-local function sync_http_auth(url,username, password)
-	module:log("debug", "sync_http_auth()");
-	require "ltn12";
-	local http = require "socket.http";
-	local https = require "ssl.https";
-	local request;
-	if string.sub(url, 1, string.len('https')) == 'https' then
-		request = https.request;
-	else
-		request = http.request;
-	end
-	local _, code, headers, status = request{
-		url = url,
-		headers = { Authorization = "Basic "..base64(username..":"..password);  }
-	};
-	if type(code) == "number" and code >= 200 and code <= 299 then
-		module:log("debug", "HTTP auth provider confirmed valid password");
-		return true;
-	else
-		module:log("debug", "HTTP auth provider returned status code: "..code);
-	end
-	return nil, "Auth failed. Invalid username or password.";
-end
-
 function provider.test_password(username, password)
 	local url = api_base:gsub("$user", username):gsub("$password", password);
 	log("debug", "Testing password for user %s at host %s with URL %s", username, host, url);
-	if (have_async) then
-		return async_http_auth(url, username, password);
-	else
-		return sync_http_auth(url, username, password);
-	end
+	return async_http_auth(url, username, password);
 end
 
 function provider.users()