Software /
code /
prosody-modules
Comparison
mod_auth_custom_http/mod_auth_custom_http.lua @ 1046:b9d47487d550
mod_auth_custom_http: Organize imports, and make the URL a config option.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 03 Jun 2013 11:09:50 -0400 |
parent | 1045:76668bb122c2 |
child | 1343:7dbde05b48a9 |
comparison
equal
deleted
inserted
replaced
1045:76668bb122c2 | 1046:b9d47487d550 |
---|---|
3 -- | 3 -- |
4 -- This project is MIT/X11 licensed. Please see the | 4 -- This project is MIT/X11 licensed. Please see the |
5 -- COPYING file in the source package for more information. | 5 -- COPYING file in the source package for more information. |
6 -- | 6 -- |
7 | 7 |
8 local log = require "util.logger".init("auth_custom_http"); | |
9 local new_sasl = require "util.sasl".new; | 8 local new_sasl = require "util.sasl".new; |
10 local nodeprep = require "util.encodings".stringprep.nodeprep; | 9 local json_encode = require "util.json"; |
10 local http = require "socket.http"; | |
11 | |
12 local options = module:get_option("auth_custom_http"); | |
13 local post_url = options and options.post_url; | |
14 assert(post_url, "No HTTP POST URL provided"); | |
11 | 15 |
12 local provider = {}; | 16 local provider = {}; |
13 | 17 |
14 function provider.test_password(username, password) | 18 function provider.test_password(username, password) |
15 return nil, "Not supported" | 19 return nil, "Not supported" |
36 end | 40 end |
37 | 41 |
38 function provider.get_sasl_handler() | 42 function provider.get_sasl_handler() |
39 local getpass_authentication_profile = { | 43 local getpass_authentication_profile = { |
40 plain_test = function(sasl, username, password, realm) | 44 plain_test = function(sasl, username, password, realm) |
41 local postdata = require "util.json".encode({ username = username, password = password }); | 45 local postdata = json_encode({ username = username, password = password }); |
42 local result = require "socket.http".request("http://example.com/path", postdata); | 46 local result = http.request(post_url, postdata); |
43 return result == "true", true; | 47 return result == "true", true; |
44 end, | 48 end, |
45 }; | 49 }; |
46 return new_sasl(module.host, getpass_authentication_profile); | 50 return new_sasl(module.host, getpass_authentication_profile); |
47 end | 51 end |