I would like to connect to my local ejabberd with the following simple python code:
from twisted.internet import reactor, protocol
from twisted.words.protocols.jabber import client, jid, xmlstream
from twisted.words.protocols.jabber.client import BasicAuthenticator
import logging
def authd(xmlstreamobj):
logging.error("authenticated")
return
def authFailed(xmlstream):
logging.error("Failed")
return
def authInvalid(xmlstream):
logging.error("Invalid")
return
def authError(xmlstream):
logging.error("Error")
print(xmlstream)
return
myJid = jid.JID("boss@localhost")
password = "boss"
myJid.resource = "onlyone"
factory = client.basicClientFactory(myJid, password)
factory.addBootstrap('//event/stream/authd' , authd)
factory.addBootstrap("//event/client/basicauth/invaliduser", authInvalid)
factory.addBootstrap("//event/client/basicauth/authfailed", authFailed)
factory.addBootstrap("//event/stream/error", authError)
reactor.connectTCP("localhost", 5222, factory)
reactor.run()
The registered users in ejabberd (using ejabberdctl registered_users localhost
command) are: admin, boss, and manager0
However, I get the following error message:
[Failure instance: Traceback (failure with no frames): <class 'twisted.words.protocols.jabber.error.StreamError'>: StreamError with condition u'not-authorized']
The ejabberd log is:
--------------------------------------------------------------------
IMPORTANT: ejabberd is going to start in LIVE (interactive) mode.
All log messages will be shown in the command shell.
You can interact with the ejabberd node if you know how to use it.
Please be extremely cautious with your actions,
and exit immediately if you are not completely sure.
To exit this LIVE mode and stop ejabberd, press:
q(). and press the Enter key
--------------------------------------------------------------------
To bypass permanently this warning, add to ejabberdctl.cfg the line:
EJABBERD_BYPASS_WARNINGS=true
Press return to continue
Erlang/OTP 22 [erts-10.7.2.12] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
Eshell V10.7.2.12 (abort with ^G)
(ejabberd@localhost)1> 2021-07-13 16:52:40.341565-06:00 [info] Loading configuration from /usr/local/etc/ejabberd/ejabberd.yml
2021-07-13 16:52:40.684051-06:00 [info] Configuration loaded successfully
2021-07-13 16:52:40.888879-06:00 [info] Got no NOTIFY_SOCKET, notifications disabled
2021-07-13 16:52:41.113546-06:00 [info] Loading modules for localhost
2021-07-13 16:52:41.132174-06:00 [warning] Mnesia backend for mod_mam is not recommended: it's limited to 2GB and often gets corrupted when reaching this limit. SQL backend is recommended. Namely, for small servers SQLite is a preferred choice because it's very easy to configure.
2021-07-13 16:52:41.199005-06:00 [info] Won't auto-announce STUN/TURN service on port 3478 (udp) without public IP address, please specify 'turn_ipv4_address' and optionally 'turn_ipv6_address'
2021-07-13 16:52:41.332173-06:00 [info] Building MQTT cache for localhost, this may take a while
2021-07-13 16:52:41.444623-06:00 [info] Waiting for Mnesia synchronization to complete
2021-07-13 16:52:41.558657-06:00 [warning] No certificate found matching localhost
2021-07-13 16:52:41.558915-06:00 [warning] No certificate found matching conference.localhost
2021-07-13 16:52:41.559022-06:00 [warning] No certificate found matching upload.localhost
2021-07-13 16:52:41.559118-06:00 [warning] No certificate found matching proxy.localhost
2021-07-13 16:52:41.559233-06:00 [warning] No certificate found matching pubsub.localhost
2021-07-13 16:52:41.559334-06:00 [info] ejabberd 21.04 is started in the node ejabberd@localhost in 1.31s
2021-07-13 16:52:41.559679-06:00 [info] Start accepting UDP connections at [::]:3478 for ejabberd_stun
2021-07-13 16:52:41.559856-06:00 [info] Start accepting TCP connections at [::]:5280 for ejabberd_http
2021-07-13 16:52:41.559871-06:00 [info] Start accepting TCP connections at [::]:5222 for ejabberd_c2s
2021-07-13 16:52:41.559890-06:00 [info] Start accepting TCP connections at 127.0.0.1:7777 for mod_proxy65_stream
2021-07-13 16:52:41.560041-06:00 [info] Start accepting TLS connections at [::]:5223 for ejabberd_c2s
2021-07-13 16:52:41.560077-06:00 [info] Start accepting TCP connections at [::]:5269 for ejabberd_s2s_in
2021-07-13 16:52:41.560131-06:00 [info] Start accepting TCP connections at [::]:1883 for mod_mqtt
2021-07-13 16:52:41.560177-06:00 [info] Start accepting TLS connections at [::]:5443 for ejabberd_http
2021-07-13 16:52:41.625170-06:00 [warning] Option 'turn_ipv4_address' is undefined and the server's hostname doesn't resolve to a public IPv4 address, most likely the TURN relay won't be working properly
2021-07-13 16:52:58.767985-06:00 [info] (<0.552.0>) Accepted connection [::ffff:127.0.0.1]:54660 -> [::ffff:127.0.0.1]:5222
2021-07-13 16:53:01.623768-06:00 [info] (<0.553.0>) Accepted connection [::ffff:127.0.0.1]:54661 -> [::ffff:127.0.0.1]:5222
2021-07-13 16:54:39.351423-06:00 [info] (<0.555.0>) Accepted connection [::ffff:127.0.0.1]:54668 -> [::ffff:127.0.0.1]:5222
2021-07-13 16:54:42.367668-06:00 [info] (<0.558.0>) Accepted connection [::ffff:127.0.0.1]:54671 -> [::ffff:127.0.0.1]:5222
The ejabberd's yml file is:
hosts:
- localhost
loglevel: 4
## If you already have certificates, list them here
# certfiles:
# - /etc/letsencrypt/live/domain.tld/fullchain.pem
# - /etc/letsencrypt/live/domain.tld/privkey.pem
listen:
-
port: 5222
ip: "::"
module: ejabberd_c2s
max_stanza_size: 262144
shaper: none
access: all
starttls_required: false
-
...
I am using the latest version of ejabberd (21.04) on my Mac. Any help would be really appreciated! thanks!
FIX: The problem was the Ejabberd version. It runs on Ejabberd 16.09 on Debian 9.