1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
-- Prosody IM
-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
--
local new_sasl = require "util.sasl".new;
local json = require "util.json";
prosody.unlock_globals();
local http = require "socket.http";
local https = require "ssl.https";
prosody.lock_globals();
local options = module:get_option("auth_custom_http");
local post_url = options and options.post_url;
assert(post_url, "No HTTP POST URL provided");
local provider = { name = "custom_http_onefang" };
function provider.test_password(username, password)
return nil, "Not supported"
end
function provider.get_password(username)
return nil, "Not supported"
end
function provider.set_password(username, password)
return nil, "Not supported"
end
function provider.user_exists(username)
return true;
end
function provider.create_user(username, password)
return nil, "Not supported"
end
function provider.delete_user(username)
return nil, "Not supported"
end
function provider.get_sasl_handler()
local getpass_authentication_profile = {
plain_test = function(sasl, username, password, realm)
local postdata = json.encode({ username = username, password = password });
local result = "";
if string.lower(post_url:sub(1, 5)) == "https" then
result = https.request(post_url, postdata);
else
result = http.request(post_url, postdata);
end
return result == "true", true;
end,
};
return new_sasl(module.host, getpass_authentication_profile);
end
module:provides("auth", provider);
|