2 -- Copyright (C) 2008 Matthew Wild
3 -- Copyright (C) 2008 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
11 local st = require "util.stanza";
12 local t_concat = table.concat;
14 module:add_feature("jabber:iq:auth");
16 module:add_iq_handler("c2s_unauthed", "jabber:iq:auth",
17 function (session, stanza)
18 local username = stanza.tags[1]:child_with_name("username");
19 local password = stanza.tags[1]:child_with_name("password");
20 local resource = stanza.tags[1]:child_with_name("resource");
21 if not (username and password and resource) then
22 local reply = st.reply(stanza);
23 session.send(reply:query("jabber:iq:auth")
26 :tag("resource"):up());
29 username, password, resource = t_concat(username), t_concat(password), t_concat(resource);
30 local reply = st.reply(stanza);
31 require "core.usermanager"
32 if usermanager.validate_credentials(session.host, username, password) then
33 -- Authentication successful!
34 local success, err = sessionmanager.make_authenticated(session, username);
36 local err_type, err_msg;
37 success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource);
39 session.send(st.error_reply(stanza, err_type, err, err_msg));
43 session.send(st.reply(stanza));
46 local reply = st.reply(stanza);
47 reply.attr.type = "error";
48 reply:tag("error", { code = "401", type = "auth" })
49 :tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" });