How can I debug Stanza.js Authentication?

364 views Asked by At

I'm currently attempting to setup an XMPP client using Stanza.js https://github.com/legastero/stanza

I have a working server that accepts connections from a Gajim client, however when attempting to connect using Stanza.js client.connect method, the server opens up a websocket connection, but no events for authentication, or session started ever fire.

The server logs do not show any plaintext password authentication attempts.

How can I actually see any of the stanza logs to debug this issue?

import * as XMPP from 'stanza';

const config = { credentials: {jid: '[jid]', password: '[password]'}, transports: {websocket: '[socketurl]', bosh: false} };
const client = XMPP.createClient(config)
client.on('raw:*', (data) => {
    console.log('data', data)
})

client.connect();

onconnect event does fire, but this is the only event that fires. Is there a way to manually trigger authentication that isn't expressed in the documentation?

3

There are 3 answers

0
Badlop On

How can I actually see any of the stanza logs to debug this issue?

If the connection is not encrypted, you can sniff the XMPP traffic with tools like

sudo tcpflow -i lo -Cg port 5222

You can force ejabberd to not allow encryption, so your clients don't use that, and you can read the network traffic.

Alternatively, in ejabbed.yml you can set this, but probably it will generate a lot of log messages:

loglevel: debug
0
Guido Simone On

The raw event handler should be able to give you the logging you want - but in your code sample, you are invoking it incorrectly. Try the following.

client.on('raw:*', (direction, data) => {
    console.log(direction, data)
})

For reference, the docs state that the callback for the raw data event handler is

(direction: incoming | outgoing, data: string) => void

So the data that you are looking for is in the second argument, but your callback only has one argument (just the direction string "incoming" or "outgoing", although you have named the argument "data").

Once you fix the logging I expect you will see the stream immediately terminates with a stream error. Your config is incorrect. The jid and password should be top level fields. Review the stanza sample code. For the options to createClient - there is no credentials object. Try the following:

const config = { jid: '[jid]', password: '[password]', transports: {websocket: '[socketurl]', bosh: false} };

Since your username and password are hidden behind an incorrect credentials object, stanza.io does not see them and you are effectively trying to connect with no username and password so no authentication is even attempted.

1
mcmcphillips On

This issue happened to be caused by a configuration problem.

The jabber server was using plain authentication. Adding an additional line to the client definition file helped. Also adding client.on('*', console.log) offered more complete server logs.

client.sasl.disable('X-OAUTH2')