xmpp4r and Iq.new_register for in-band registration

953 views Asked by At

I've been having trouble using xmpp4r to do in-band registration following the SO thread here:

XMPP transport to another protocol

The problem comes down to that I get a NoMethodError Exception error for new_register when I run the following code:

require "xmpp4r"
require "xmpp4r/client" 
require "xmpp4r/iq"

def in_band_reg

     chat_name = 'testChatName'
     password  = 'pword'

     reg    = Jabber::Iq.new_register(chat_name, password)

end

NoMethodError Exception: undefined method `new_register' for Jabber::Iq:Class

In the xmpp4r gem in the file iq.rb I can see the new_register method defined as:

 def Iq.new_register(username=nil, password=nil)
        ...
 end

but when I examine the class's methods I'm not able to see the new_register method. I.E.

Jabber::Iq.singleton_methods(false)
["new_authset", "new_rosterget", "new_vcard", "new_rosterset", "import",    "new_authset_digest", "new_query", "add_elementclass", "new_browseget"]

Jabber::Iq.public_instance_methods(false)
 ["query=", "queryns", "set_type", "type", "typed_add", "type=", "query", "vcard"]

Jabber::Iq.respond_to?("new_register")
false

Any idea why I can't access the new_register method in 'xmpp4r/iq' ?

2

There are 2 answers

1
James Testa On BEST ANSWER

I got this working by just coding it up myself. First connect a client that can in-band register new users:

jid = JID::new('[email protected]/res')
client = Client::new(jid, false)
client.connect
client.auth("admin_password")

then have that client register a new user by sending an in-band message

iqr = Iq.new(:set)
qr = IqQuery.new
qr.add_namespace('jabber:iq:register')
username = 'new_user'
password = 'new_user_password'
qr.add(REXML::Element.new('username').add_text(username))
qr.add(REXML::Element.new('password').add_text(password))
iqr.add(qr)
client.send iqr
1
Joe Hildebrand On

What version of xmpp4r are you using? Have you tried the GitHub version?

gem sources -a http://gems.github.com (you only need to do this once!)
gem install ln-xmpp4r