Unsuccessful user registration for ejabberd server

Client app: iOS Swift iphone

Server: ejabberd

Swift code:

import UIKit
import XMPPFramework

class RegisterViewController: UIViewController, XMPPStreamDelegate {

    var stream:XMPPStream!
    let xmppRosterStorage = XMPPRosterCoreDataStorage()
    var xmppRoster: XMPPRoster!
    
    @IBOutlet weak var userNameTextField: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        xmppRoster = XMPPRoster(rosterStorage: xmppRosterStorage)
        stream = XMPPStream()
        stream.hostName = "XXXXXXXXX"
        stream.addDelegate(self, delegateQueue: DispatchQueue.main)
        xmppRoster.activate(stream)
        
    }

    @IBAction func registrationBtnClicked(_ sender: Any) {
        
        stream.myJID = XMPPJID(string:userNameTextField.text) //here textField contains user9@localhost
        do {
            try stream.connect(withTimeout: 30)
        }
        catch {
            print("error occured in connecting")
        }

  }
    
    public func xmppStreamDidRegister(_ sender: XMPPStream!){
        print("User registered successfully")
    }
    
    
    public func xmppStream(_ sender: XMPPStream!, didNotRegister error: DDXMLElement!){
        print("User registration failed")
        print(error)
    }
    
    func xmppStreamWillConnect(_ sender: XMPPStream!) {
        print("will connect")
    }
    
    func xmppStreamConnectDidTimeout(_ sender: XMPPStream!) {
        print("timeout:")
    }
    
    func xmppStreamDidConnect(_ sender: XMPPStream!) {
        print("connected")
        
        do {
            try sender.authenticate(withPassword: "pass")
        }
        catch {
            print("catch")
        }
}
    
    func xmppStreamDidAuthenticate(_ sender: XMPPStream!) {
        print("auth done")
        sender.send(XMPPPresence())
    }
    
    
    func xmppStream(_ sender: XMPPStream!, didNotAuthenticate error: DDXMLElement!) {
        print("dint not auth")
        
        if stream.supportsInBandRegistration(){
            stream.myJID = XMPPJID(string:userNameTextField.text)
            do{
                try stream.register(withPassword: "pass")
            }
            catch{
                print("Registration failed")
            }
        }

        
    }
}

Output and Error:

will connect
connected
dint not auth
User registration failed
<iq xmlns="jabber:client" type="error">
  <query xmlns="jabber:iq:register">
    <username>user9</username>
    <password>pass</password>
  </query>
  <error code="400" type="modify">
    <bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
    <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Missing attribute 'id' in tag &lt;iq/&gt; qualified by namespace 'jabber:client'</text>
  </error>
</iq>

It means exactly that. The IQ

It means exactly that. The IQ element should have an 'id' attribute, usually with a random value, for example:

<iq xmlns="jabber:client" type="set" id="595873930">
  <query xmlns="jabber:iq:register">
...

Hi badlop, please check

Hi badlop,

please check my code:

var xml: String = "<iq xmlns='jabber:client' type='set' id='reg9'>"
        xml.append("<query xmlns='jabber:iq:register'>")
        xml.append("<username>user9@localhost</username><password>simple_password</password>")
        xml.append("</query></iq>")

let element = DDXMLElement.element(withName: "registration", stringValue: xml) as! DDXMLElement

if stream.supportsInBandRegistration(){
            do {
               
                try sender.register(withElements:[element])
}
            catch {
                print("registration failed")
               
            }
        }

same error after adding 'id'

Maybe it is some bug in the

Maybe it is some bug in the ejabberd version you are using. Which version are you using? I try with 17.01 and works correctly.

Hi badlop, the following

Hi badlop, the following error occurs after many trials:

Code:

        if stream.supportsInBandRegistration(){
            do {
                       let toStr: String = sender.myJID.domain
                    let query = DDXMLElement.element(withName: "query",stringValue:
                  "jabber:iq:register") as! DDXMLElement
                                            
                  var iq: XMPPIQ = XMPPIQ(type: "get", to: XMPPJID(string:toStr), elementID:
                   sender.generateUUID(), child: query)
               
                                sender.send(iq)
            }
            catch {
                print("catch")
               
            }
        }

Error:

iq send successfully
iq = <iq xmlns="jabber:client" from="localhost.org" type="error" id="6A009D1D-CC57-4C73-ABAE-C4CAA6E97E9D"><query>jabber:iq:register</query><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Authentication required</text></error></iq>

In band registration is true for the above code. Please help me to solve this.

I don't know Swift

I don't know Swift

Hi badlop, Ok. I

Hi badlop,

Ok. I am getting service-unavailable even if in-band registration is true. What are the reasons for above error. Please specify. Then i can debug it. Thank you so much for your reply.

Please specify the

Please specify the possibilities for the error. Do we need any changes in .yml file related to that?.

Hi badlop, I

Hi badlop,

I successfully register a user. This is my code:

if stream.supportsInBandRegistration(){
            let xmlstring: String = String("<query xmlns='jabber:iq:register'><username>\(userNameTextField.text!)</username><password>\(passwordTextField.text!)</password><email>user@enterpi.com</email></query>")
            let newQuery = try! DDXMLElement(xmlString: xmlstring)
            let newIq = XMPPIQ(type: "set", to: XMPPJID(string:"localhost"), elementID: stream.generateUUID(), child: newQuery)
            stream.send(newIq)
        }

Thank you so much for your valuable support.

Hi Sathi , i follow your

Hi Sathi , i follow your code
//////////////////////////////////////////////

if stream.supportsInBandRegistration(){
let xmlstring: String = String("\(userNameTextField.text!)\(passwordTextField.text!)user@enterpi.com")
let newQuery = try! DDXMLElement(xmlString: xmlstring)
let newIq = XMPPIQ(type: "set", to: XMPPJID(string:"localhost"), elementID: stream.generateUUID(), child: newQuery)
stream.send(newIq)
}
////////////////////////////////////

but after send request i didn't get any error or any Output ..plz Help me in XMPP Registration

Hi Sathi , i follow your

Hi Sathi , i follow your code
//////////////////////////////////////////////

if stream.supportsInBandRegistration(){
let xmlstring: String = String("\(userNameTextField.text!)\(passwordTextField.text!)user@enterpi.com")
let newQuery = try! DDXMLElement(xmlString: xmlstring)
let newIq = XMPPIQ(type: "set", to: XMPPJID(string:"localhost"), elementID: stream.generateUUID(), child: newQuery)
stream.send(newIq)
}
////////////////////////////////////

but after send request i didn't get any error or any Output ..plz Help me in XMPP Registration

Syndicate content