how to register a new account via node-xmpp #41

Closed
minehp opened this Issue Oct 27, 2011 · 7 comments

5 participants

@minehp

i read XEP-0077
if i wan to register i must send " iq " with get type, like:

ejabberd.send(new xmpp.Element('iq',{type:'get',id:'reg1',to:'test.server'}).c('query',{xmlns:'jabber:iq:register'}));

and i got result like this :

{ name: 'iq',
parent: null,
attrs:
{ from: 'admin@test.server',
to: 'admin@test.server/38928777511319686566520895',
id: 'reg1',
type: 'result',
xmlns: 'jabber:client',
'xmlns:stream': 'http://etherx.jabber.org/streams' },
children:
[ { name: 'query',
parent: [Circular],
attrs: [Object],
children: [Object] } ] }

with children like :

[ { name: 'instructions',
parent:
{ name: 'query',
parent: [Object],
attrs: [Object],
children: [Circular] },
attrs: {},
children: [ 'Choose a username and password to register with this server' ] },
{ name: 'username',
parent:
{ name: 'query',
parent: [Object],
attrs: [Object],
children: [Circular] },
attrs: {},
children: [ 'admin' ] },
{ name: 'password',
parent:
{ name: 'query',
parent: [Object],
attrs: [Object],
children: [Circular] },
attrs: {},
children: [] },
{ name: 'registered',
parent:
{ name: 'query',
parent: [Object],
attrs: [Object],
children: [Circular] },
attrs: {},
children: [] } ]

adn then i send this code ( like XEP-0077 example ) :

ejabberd.send(new xmpp.Element('iq',{type:'set',id:'reg1'}).c('query',{xmlns:'jabber:iq:register'}).c('username').t('alow').up().c('password').t('testa'));

why i got error result like this

[ { name: 'query',
parent:
{ name: 'iq',
parent: null,
attrs: [Object],
children: [Circular] },
attrs: { xmlns: 'jabber:iq:register' },
children: [ [Object], [Object] ] },
{ name: 'error',
parent:
{ name: 'iq',
parent: null,
attrs: [Object],
children: [Circular] },
attrs: { code: '403', type: 'auth' },
children: [ [Object] ] } ]

what i miss something....?
i already used super user in all code...

@astro
node-XMPP member

Registering must be done before authentication. Patches will be welcomed!

@minehp

i'm waiting the patches... thanks

@jhartikainen

Not really an optimal solution, but you can get started by using something like this:

//Create a connection to the jabber server:
var host = 'some.jabber.server';
var port = 5222;
var socket = net.createConnection(port, host);
var connection = new xmpp.Connection.Connection(socket);

//This property needs to be set to the host of the Jabber server in order for this to work:
connection.streamTo = host;

//Start the jabber stream, must be called to initialize the connection
connection.startStream();

//Create iq's and send:
var iq = new xmpp.Element('iq', { type: 'get', id: 'regl', to: host }).c('query', { xmlns: 'jabber:iq:register' }).up();
connection.send(iq);

This will allow you to send iq's without registering. However, you will need to listen for the 'data' event on the connection and process the responses yourself.

I may do a patch for this later. I already managed to hack the Client to work in a non-authorized state so you can use it instead of the Connection, but it might not be a very clean solution.

@astro
node-XMPP member

Alright, too many people seem to long for this feature. Please take a look at 129884a. It introduces a register option and will authenticate after successful account registration.

@astro astro closed this Jan 4, 2012
@dudochkin-victor

Riegister at less have to situation result & error. They are not handled in Client.onStanza here fast patch for sovle this:

...... here the bottom of function
} else if (this.state == STATE_ONLINE) {
this.emit('stanza', stanza);
} else if (stanza.is('iq') && stanza.attrs.type == 'result')
{
// Handle registrations success
this.emit('stanza', stanza);
} else if (stanza.is('iq') && stanza.attrs.type == 'error')
{
// Handle registrations error
this.emit('error', stanza);
} else
{
util.puts('UNHANDLED' + stanza.toString());
}

At bottom of this function I was added two state handlings and one for development purposes. Please accept them. Just dont want to fork.

@lloydwatkin
node-XMPP member

Hi @dudochkin-victor thanks for the patch.

Would you be able to turn this into a pull request with appropriate tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment