in-band registration

176 views
Skip to first unread message

John Greene

unread,
Jul 8, 2009, 2:10:45 PM7/8/09
to str...@googlegroups.com
Hello Again,

I understand there isn't a built-in means to register a new account on a jabber server using Strophe.js, so I'm essentially faking it:
  • log in anonymously
  • use that connection to attempt to register an account for the username I want
  • disconnect
  • reconnect as the newly registered user
It works adequately well as a workaround, but strange issue: it doesn't work when I reload the page.  That is to say, I get a "Not Authorized" message back from the server, but if I wait around a minute and reload, it works.

Here is the code I'm using, loosely based upon the example provided by Strophe.js, somewhat abridged for readability.  If anyone knows a better way to do this, I'd love to know.
$(document).ready(function () {
    connection = new Strophe.Connection(BOSH_SERVICE);
    connection.connect(
                       'somehost',
                       null,
                       onConnect
                       );
});


function onConnect(status) {
  if (status == Strophe.Status.DISCONNECTED) {
    // this means i've logged off as anonymous user, so log back in properly
    connection.connect('someuser@somehost',
		       'somepassword',
		       onConnect);
    connection.addHandler(registerCreds, 'jabber:iq:register', 'iq', null, 'reg1', null);
  } else if (status == Strophe.Status.CONNECTED) {
    if(!REGISTERED) {
      // i'm logged in anonymously, so off i go to register
      register();
    }
    connection.addHandler(registerCreds, 'jabber:iq:register', 'iq', null, 'reg1', null);
    connection.addHandler(acknowledgeCreds, 'jabber:iq:register', 'iq', null, 'reg2', null);
    $().mousemove(function(e){
	sendMessageToListener(e.pageX, e.pageY);
      })
    }
}


function register() {
  var iq = $iq(
               {
                 "id":'reg1',
                   "type":"get"
                   })
    .c("query", {"xmlns":"jabber:iq:register"});
  connection.send(iq);
  return true;     
}


function registerCreds(msg) {
  var iq = $iq(
               {
                 "id":'reg2',
                   "type":"set"
                   })
   .c("query", {"xmlns":"jabber:iq:register"})
   .c('username').t(MY.user)
   .up()
   .c('password').t(MY.user);
  connection.send(iq);
  return true;
}



function acknowledgeCreds(msg) {
  REGISTERED = true;
  var iq = $iq(
               {
                 'id':'unreg1',
                   'type':'set',
                   'from': connection.jid
                   })
    .c('query',{'xmlns':'jabber:iq:register'})
    .c('remove');
  connection.send(iq);
  return true;
} 
  

Thanks,

John

Jack Moffitt

unread,
Jul 8, 2009, 3:19:41 PM7/8/09
to str...@googlegroups.com
> It works adequately well as a workaround, but strange issue: it doesn't work
> when I reload the page.  That is to say, I get a "Not Authorized" message
> back from the server, but if I wait around a minute and reload, it works.

I know that jabber.org added a parameter to limit in band registration
attempts. My guess is that you are hitting the rate limit for
registrations. If you control the server you might try disabling that
and see if that fixes the problem.

Thanks for posting the workaround, though. I never knew you could do
in-band registration when authenticated as SASL ANONYMOUS.

jack.

Alex Clemesha

unread,
Jul 8, 2009, 3:35:15 PM7/8/09
to str...@googlegroups.com
John,

I hit up against this problem too, and I solved it by changing
the "registration_timeout" in my "ejabberd.cfg".
(This obviously assumes you are using Ejabberd)


Around line 360 in "ejabberd.cfg":

%% Every username can be registered via in-band registration:
%% To disable in-band registration, replace 'allow' with 'deny'.
{access, register, [{allow, all}]}.
{registration_timeout, infinity}.


hope this helps some,
Alex
--
Alex Clemesha
clemesha.org

John Greene

unread,
Jul 8, 2009, 4:05:28 PM7/8/09
to str...@googlegroups.com

Alex Clemesha wrote:
> John,
>
> I hit up against this problem too, and I solved it by changing
> the "registration_timeout" in my "ejabberd.cfg".
> (This obviously assumes you are using Ejabberd)
>
>
> Around line 360 in "ejabberd.cfg":
>
> %% Every username can be registered via in-band registration:
> %% To disable in-band registration, replace 'allow' with 'deny'.
> {access, register, [{allow, all}]}.
> {registration_timeout, infinity}.
>
>
> hope this helps some,
> Alex
>
hmm, that helped a bit, but digging in a bit more it turns out that
(probably also due to a server setting) the user isn't disconnecting, so
when the Strophe client tries to reconnect, it gets an auth failure. I
can work around that by logging in with pidgin, then logging right out.
Then the Strophe client works.

Jack Moffitt

unread,
Jul 8, 2009, 4:24:29 PM7/8/09
to str...@googlegroups.com
> hmm, that helped a bit, but digging in a bit more it turns out that
> (probably also due to a server setting) the user isn't disconnecting, so
> when the Strophe client tries to reconnect, it gets an auth failure.  I
> can work around that by logging in with pidgin, then logging right out.
> Then the Strophe client works.

You aren't getting disconnected on a reload? That sounds very weird.
On a reload the old client may not get disconnected due to inactivity
timeouts, but Strophe should not have any knowledge of that at all.

Are you calling disconnect()? Perhaps turn on the debugging info (set
Strophe.log to function (lvl, msg) { console.log(msg); } for instance)
and find out what sequence of events is from its perspective?

jack.

Reply all
Reply to author
Forward
0 new messages