Diff

mod_auth_http_async/mod_auth_http_async.lua @ 2750:1d139e33c502

mod_auth_http_async: Updated sync_http_auth function to accept username and password and send those as a basic authentication header
author Matt Loupe <mloupe2@gmail.com>
date Wed, 23 Aug 2017 14:31:55 -0500
parent 2630:96eb1c4f9ff7
child 2811:39156d6f7268
line wrap: on
line diff
--- a/mod_auth_http_async/mod_auth_http_async.lua	Tue Aug 22 20:25:58 2017 +0200
+++ b/mod_auth_http_async/mod_auth_http_async.lua	Wed Aug 23 14:31:55 2017 -0500
@@ -28,6 +28,7 @@
 end
 
 local function async_http_auth(url, username, password)
+module:log("debug", "async_http_auth()");
 	local http = require "net.http";
 	local wait, done = async.waiter();
 	local content, code, request, response;
@@ -49,7 +50,8 @@
 	return nil, "Auth failed. Invalid username or password.";
 end
 
-local function sync_http_auth(url)
+local function sync_http_auth(url,username, password)
+module:log("debug", "sync_http_auth()");
 	local http = require "socket.http";
 	local https = require "ssl.https";
 	local request;
@@ -60,7 +62,7 @@
 	end
 	local _, code, headers, status = request{
 		url = url,
-		headers = { ACCEPT = "application/json, text/plain, */*"; }
+		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");
@@ -77,7 +79,7 @@
 	if (have_async) then
 		return async_http_auth(url, username, password);
 	else
-		return sync_http_auth(url);
+		return sync_http_auth(url, username, password);
 	end
 end
 
@@ -111,4 +113,4 @@
 	});
 end
 
-module:provides("auth", provider);
+module:provides("auth", provider);
\ No newline at end of file