1
votes

So I have a little JavaScript/Strophejs xmpp client which connects to an ejabberd server. So far, I have created users in the ejabberd web admin, e.g. I created user [email protected] and user [email protected].

My client supports loging in to one of these existing accounts, and sending messages between these accounts/users.

I would also, however, like for the ability to create Users on the server from an HTML form, where the user enters his desired jid and password.

In xmpp, this is referred to as an in-band registration (http://xmpp.org/extensions/xep-0077.html).

Now, here is the basic scenario when a User logs in to an existing account:

$(document).ready(function () {
$('#SignIn').bind('click', function () {
    $(document).trigger('connect', { 
                                    jid: $('#LogineMail').val(), password: $('#LoginPassword_f').val()
                                    }
                        );
                        });
});

So, above code triggers 'connect', which looks like this:

$(document).bind('connect', function (ev, data) {
console.log('connect fired');
var conn = new Strophe.Connection("http://bosh.metajack.im:5280/xmpp-httpbind");
conn.connect(data.jid, data.password, function (status) {
    console.log('callback being done');
    if (status === Strophe.Status.CONNECTED) {
        alert('connected!');
        $(document).trigger('connected');
        alert('Connected successfully');
    } else if (status === Strophe.Status.DISCONNECTED) {
        $(document).trigger('disconnected');
    }
    else
    {
        Hello.log("error");
        console.log('error');
    }
});

Hello.connection = conn;
});

I.e., this creates a new Strophe.connection, and signs in with a given jid and password. I can then send messages.

However, the situation for an in-band-registration is a bit different. XEP-0077 states that:

3.1 Entity Registers with a Host

In order to determine which fields are required for registration with a host, an entity SHOULD first send an IQ get to the host. The entity SHOULD NOT attempt to guess at the required fields by first sending an IQ set, since the nature of the required data is subject to service provisioning.

Example 1. Entity Requests Registration Fields from Host

<iq type='get' id='reg1' to='shakespeare.lit'>
  <query xmlns='jabber:iq:register'/>
</iq>

This means, that I need to be able to send an IQ request, and receive a response, before I am logged in to the server as a user, since, obviously, if I am a user requesting an account on a server, I probably dont have an account on the server yet, and thus cant sign in with a jid/password combo.

How can one adress this? What are the usual steps, regarding connection and stanza sending for in-bound regsitration? For example, should I have some kind of admin account on the server, that I then log into from code when wanting to add a new user, and use this admin account to get the requirements/fields necessary for in-band regsitration and register the new user? Or what would a good/standard approach be?

Thanks and best regards,

Chris

Edit: I just found the strophe.register.js plugin, which I am trying to use now. However I am getting an error in strophe.register.js code, not in my own.

This is what my code looks like for registering:

$('#JoinSend').bind('click', function () {
    var tempConn = new Strophe.Connection("http://bosh.metajack.im:5280/xmpp-httpbind");
    tempConn.register.connect("testserver.host56.com", function (status) {
        if (status === Strophe.Status.REGISTER) {
            // fill out the fields
            connection.register.fields.username = "juliet";
            connection.register.fields.password = "R0m30";
            // calling submit will continue the registration process
            connection.register.submit();
        } else if (status === Strophe.Status.REGISTERED) {
            console.log("registered!");
            // calling login will authenticate the registered JID.
            connection.authenticate();
        } else if (status === Strophe.Status.CONFLICT) {
            console.log("Contact already existed!");
        } else if (status === Strophe.Status.NOTACCEPTABLE) {
            console.log("Registration form not properly filled out.")
        } else if (status === Strophe.Status.REGIFAIL) {
            console.log("The Server does not support In-Band Registration")
        } else if (status === Strophe.Status.CONNECTED) {
            // do something after successful authentication
        } else {
            // Do other stuff
        }
    });
    });

I get the following error in chrome JS console:

Uncaught TypeError: Cannot read property 'bind' of undefined : strophe.register.js:90.

Not sure if I am missing something, or maybe strophe.register.js has additional dependencies?

I am using strophe.register.js from here: https://github.com/strophe/strophejs-plugins/blob/master/register/strophe.register.js

1

1 Answers

3
votes

There is a difference between being 'connected' to a server and the connection being 'authenticated'. In order to perform in-band registration, you just need to be connect, perform no authentication step and then simply send the stanzas to perform the registration. If the server supports in-band registration, he will allow that (while he should prevent any communication with other XMPP entities while the connection is not authenticated).