Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SASL authorization failing while connecting to XMPP server

I am trying to connect to gmail using SMACK API through XMPP server. but getting the

error : SASL authentication failed using mechanism PLAIN

you can check a glimpse of code. I got it from net only

ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
connection = new XMPPConnection(connConfig);
connection.connect();
SASLAuthentication.supportSASLMechanism("PLAIN", 0);

I checked in the smack debug window. it says in XML :

< invalid-authzid />

I am already having account on gmail and my gtalk is also running.

like image 750
SPB Avatar asked Sep 17 '10 09:09

SPB


2 Answers

You need to set the authentication before you connect viz

SASLAuthentication.supportSASLMechanism("PLAIN", 0);

must appear before connection.connect().

See my blog.

like image 73
Chuk Lee Avatar answered Sep 20 '22 04:09

Chuk Lee


    ConnectionConfiguration cc = new ConnectionConfiguration(
            "vietnam.agilemobile.com", 5222, vietnam.agilemobile.com");
    XMPPConnection connection = new XMPPConnection(cc);
    try {
        SASLAuthentication.supportSASLMechanism("PLAIN", 0);
        connection.connect();
        Log.e("LOGIN", "" + 111);
        // You have to put this code before you login
        Log.e("LOGIN", "" + 222);
        // You have to specify your gmail addres WITH @gmail.com at the end
        connection.login("nemodo", "123456", "resource");
        Log.e("LOGIN", "" + 333);
        // See if you are authenticated
        System.out.println(connection.isAuthenticated());

    } catch (XMPPException e1) {
        e1.printStackTrace();
    }

I also get this mistake, but i can not work.

like image 28
BaDo Avatar answered Sep 17 '22 04:09

BaDo