简体   繁体   中英

Unable to register an user in Ejabberd using XMPPFramework

I am writing a iOS client using XMPPFramework. I am not able to redister an user. I have configured ejabberd server and it is up and running. I dont have any issues with it. I am able to register an user from the web portal of Ejabberd. But the issue arises when I try registering an user from the iOS client. The server log is below

=INFO REPORT==== 2014-04-26 12:06:43 ===
I(<0.380.0>:ejabberd_listener:281) : (#Port<0.3865>) Accepted connection {{211,28,44,250},49742} -> {{172,31,0,235},5222}

=INFO REPORT==== 2014-04-26 12:06:44 ===
I(<0.424.0>:ejabberd_c2s:802) : ({socket_state,gen_tcp,#Port<0.3865>,<0.423.0>}) Failed authentication for xcc@localhost

The authmethod is odbc. Since I use mysql for data and message storage.

The log which I capture from the client is below

 2014-04-25 20:46:49:384 iPhoneXMPP[1971:90b] SEND: <auth       xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="DIGEST-MD5"/>
 2014-04-25 20:46:49:620 iPhoneXMPP[1971:650b] RECV: <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">bm9uY2U9IjMzNzkzODUwOTEiLHFvcD0iYXV0aCIsY2hhcnNldD11dGYtOCxhbGdvcml0aG09bWQ1LXNlc3M=</challenge>
 2014-04-25 20:46:49:621 iPhoneXMPP[1971:650b] SEND: <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dXNlcm5hbWU9ImlvYzEiLHJlYWxtPSJsb2NhbGhvc3QiLG5vbmNlPSIzMzc5Mzg1MDkxIixjbm9uY2U9IkMzN0U0NjlBLTg0RUUtNEY3RS1CNTEzLTM5RUJFREU0NzQ3NCIsbmM9MDAwMDAwMDEscW9wPWF1dGgsZGlnZXN0LXVyaT0ieG1wcC9sb2NhbGhvc3QiLHJlc3BvbnNlPTQzYTY5OTVlZmY2Y2UwNzA0YmJkNWM4OWZiNGU5ZDQ1LGNoYXJzZXQ9dXRmLTg=</response>
2014-04-25 20:46:49:865 iPhoneXMPP[1971:4953] RECV: <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
2014-04-25 20:46:49:865 iPhoneXMPP[1971:90b] iPhoneXMPPAppDelegate: xmppStream:didNotAuthenticate:
2014-04-25 20:46:49.865 iPhoneXMPP[1971:90b] num--680
2014-04-25 20:46:49.866 iPhoneXMPP[1971:90b] elements--(
"<username>ioc1@localhost</username>",
"<password>ioc</password>",
"<name>ioc1@localhost</name>",
"<accounttype>1</accounttype>",
"<devicetoken>680</devicetoken>",
"<email>ioc1@localhost</email>"
)

The important line to not is below

2014-04-25 20:46:49:865 iPhoneXMPP[1971:4953] RECV:

I am using registerwithpassword method and I am really confused why I am not able to register. I believe auth_method will come into play only when trying to login as it need some authentication mechanism to login. But here I am just registering. Why I am not able to register. I believe it is not an issue with the hostname since I am getting a log line that "Failed authentication for @localhost"

It means I am hitting the server. Is there something I am missing in the ejabberd.cfg file which is blocking me.

Please note: Also, I tried authmethod as internal (though in help it is mentioned it is related to mnesia - the built in DB and I am using mysql) and still got the same issue and I believe the client is not able to register a user due to some connection settings.

Is the issue is on the client end or server end. Please guide me. Thanks for your time.

In order for registration to work, you would need to ensure that the stream is connected. I have shown below a sample of how to register a user.

- (IBAction)signUpButtonPressed:(UIButton *)sender {
   // when the sign up button is pressed, set the JID for the xmpp stream
    [self.xmppStream setMyJID:[XMPPJID jidWithString:jid]];
     // check that the stream is not disconnected
     if([self.xmppStream isDisconnected]){
          // stream is not connected, attempt to connect
         if (![self.xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) {
             NSlog(@"Error connecting: %@", error);
          }
          // after stream connects, call [self beginRegistration] in xmppStreamDidConnect delegate method
     } else {
          [self beginRegistration];
     }
 }    

-(void) beginRegistration {
  // check if inband registration is supported
   if (self.xmppStream.supportsInBandRegistration) {
       if (![self.xmppStream registerWithPassword:password error:&error]) {
             NSlog(@"Registration error: %@", error);
       }
   } else {
       NSlog(@"Inband registration is not supported");
   }
}

To check that registration was successful, use xmppStreamDidRegister:(XMPPStream *)sender and xmppStream:(XMPPStream *)sender didNotRegister:(NSXMLElement *)error delegate methods.

Let me know if this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM