-module:add_event_hook("stream-features",
- function (session, features)
- if not session.username then
- features:tag("mechanisms", mechanisms_attr);
- -- TODO: Provide PLAIN only if TLS is active, this is a SHOULD from the introduction of RFC 4616. This behavior could be overridden via configuration but will issuing a warning or so.
- features:tag("mechanism"):text("PLAIN"):up();
- features:tag("mechanism"):text("DIGEST-MD5"):up();
- features:up();
- else
- features:tag("bind", bind_attr):tag("required"):up():up();
- features:tag("session", xmpp_session_attr):up();
- end
- end);
-
-module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-bind",
+module:add_event_hook("stream-features",
+ function (session, features)
+ if not session.username then
+ if secure_auth_only and not session.secure then
+ return;
+ end
+ if config.get(session.host or "*", "core", "anonymous_login") then
+ session.sasl_handler = new_sasl(session.host, anonymous_authentication_profile);
+ else
+ session.sasl_handler = new_sasl(session.host, default_authentication_profile);
+ if not session.secure then
+ session.sasl_handler:forbidden({"PLAIN"});
+ end
+ end
+ features:tag("mechanisms", mechanisms_attr);
+ for k, v in pairs(session.sasl_handler:mechanisms()) do
+ features:tag("mechanism"):text(v):up();
+ end
+ features:up();
+ else
+ features:tag("bind", bind_attr):tag("required"):up():up();
+ features:tag("session", xmpp_session_attr):tag("optional"):up():up();
+ end
+ end);
+
+module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-bind",