Software /
code /
prosody-modules
Annotate
mod_auth_custom_http/mod_auth_custom_http.lua @ 1043:809f7d46ad5c
mod_auth_custom_http: Initial commit.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 03 Jun 2013 16:39:40 +0500 |
child | 1044:fcb9bf7ac107 |
rev | line source |
---|---|
1043
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 -- Prosody IM |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2010 Waqas Hussain |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 -- |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 -- This project is MIT/X11 licensed. Please see the |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 -- COPYING file in the source package for more information. |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 -- |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 local datamanager = require "util.datamanager"; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 local log = require "util.logger".init("auth_custom_http"); |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local type = type; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local error = error; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 local ipairs = ipairs; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 local hashes = require "util.hashes"; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 local jid_bare = require "util.jid".bare; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 local config = require "core.configmanager"; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 local usermanager = require "core.usermanager"; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 local new_sasl = require "util.sasl".new; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 local nodeprep = require "util.encodings".stringprep.nodeprep; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 local hosts = hosts; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 local prosody = _G.prosody; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 local provider = {}; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 function provider.test_password(username, password) |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 return nil, "Not supported" |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 end |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 function provider.get_password(username) |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 return nil, "Not supported" |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 end |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 function provider.set_password(username, password) |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 return nil, "Not supported" |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 end |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 function provider.user_exists(username) |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 return true; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 end |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 function provider.create_user(username, password) |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 return nil, "Not supported" |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 end |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 function provider.delete_user(username) |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 return nil, "Not supported" |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 end |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 function provider.get_sasl_handler() |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 local getpass_authentication_profile = { |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 plain_test = function(sasl, username, password, realm) |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 local prepped_username = nodeprep(username); |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 if not prepped_username then |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 log("debug", "NODEprep failed on username: %s", username); |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 return "", nil; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 end |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 local postdata = require "util.json".encode({ username = username, password = password }); |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 local result = require "socket.http".request("http://example.com/path", postdata); |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 return result == "true", true; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 end, |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 }; |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 return new_sasl(module.host, getpass_authentication_profile); |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 end |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 module:provides("auth", provider); |
809f7d46ad5c
mod_auth_custom_http: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 |