Smack and GoogleTalk SASL Error

Hi,

I’m new to smack and just wanted to start a connection. I would like to connect to GoogleTalk and searched this forum to get it started but it still doesn’t work.

Here is what I did:

ConnectionConfiguration config = new ConnectionConfiguration(“talk.google.com”, 5222, “googlemail.com”);

config.setCompressionEnabled(

true);

config.setSASLAuthenticationEnabled(

true);

XMPPConnection connection =

new XMPPConnection(config);

try


connection.connect();

SASLAuthentication.supportSASLMechanism(

{

connection.login(

“PLAIN”,0);

"account@googlemail.com", “password”);

} catch (XMPPException e) {

}

e.printStackTrace();

I get the error:

SASL authentication failed using mechanism PLAIN:

at org.jivesoftware.smack.SASLAuthentication.authenticate(

at org.jivesoftware.smack.XMPPConnection.login(

SASLAuthentication.java:325)

at org.jivesoftware.smack.XMPPConnection.login(

XMPPConnection.java:395)

at dfh.main(

XMPPConnection.java:349)

dfh.java:22)

Thanks for your help

Hi, it took a while to me, but I was able to figure out this solution. As this thread is still open, I’ll put my working code here in case other people are having the same problem.

I was using version 3.0.0 because of this error… now it works with 3.1.0

The gratest problem (in may case) was that I wasn’t setting my connection properly (SASLAuth MUST be false).

Here is it:

public static void main(String[] args)

{

System.out.println(“Starting…”);

ConnectionConfiguration connCfg = new ConnectionConfiguration(“talk.google.com”, 5222, “gmail.com”);

connCfg.setSASLAuthenticationEnabled(false);

XMPPConnection connection = new XMPPConnection(connCfg);

System.out.println(“Connecting…”);

try

{

connection.connect();

System.out.println("Connected to " + connection.getHost());

}

catch (XMPPException ex)

{

System.out.println("Failed to connect to " + connection.getHost() + ": " + ex.getMessage());

System.exit(1);

}

System.out.println(“Loggin in…”);

try

{

connection.login(“vgartner”, “#$CxFm(6KD”);

// SASLAuthentication.supportSASLMechanism(“PLAIN”,0);

System.out.println("Logged in as " + connection.getUser());

Presence presence = new Presence(Presence.Type.available);

connection.sendPacket(presence);

}

catch (XMPPException ex)

{

System.out.println("Failed to log in as " + connection.getUser() + ": " + ex.getMessage());

System.exit(1);

}

Roster roster = connection.getRoster();

Collection entries = roster.getEntries();

System.out.println("\n\n" + entries.size() + " buddy(ies):");

for (RosterEntry r : entries)

{

System.out.println(r.getUser());

}

connection.disconnect();

}

public static void main(String[] args)

{

    System.out.println("Starting...");

    ConnectionConfiguration connCfg = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");

    // This should be the problem in most cases I saw.

    connCfg.setSASLAuthenticationEnabled(false);

    XMPPConnection connection = new XMPPConnection(connCfg);

    System.out.println("Connecting...");

    try

    {

        connection.connect();

        System.out.println("Connected to " + connection.getHost());

    }

    catch (XMPPException ex)

    {

        System.out.println("Failed to connect to " + connection.getHost() + ": " + ex.getMessage());

        System.exit(1);

    }

    System.out.println("Loggin in...");

    try

    {

        connection.login(userName, password);

        System.out.println("Logged in as " + connection.getUser());

    }

    catch (XMPPException ex)

    {

        System.out.println("Failed to log in as " + connection.getUser() + ": " + ex.getMessage());

        System.exit(1);

    }

    Roster roster = connection.getRoster();

    Collection<RosterEntry> entries = roster.getEntries();

    System.out.println("\n\n" + entries.size() + " buddies:");

    for (RosterEntry r : entries)

    {

        System.out.println(r.getUser());

    }

    connection.disconnect();

}

I hope that it helps.

Best regards,

Vilson C. Gärtner

Hello, can you tell me the format of the username you are using. I tried this way but ti says

jid-malformed(400) Malformed JID 'username@gmail.com': node contains illegal character '@'

I can’t find any info of the right JID format. I also tried with just “username”, "username@googlemail.com" but it won’t work.

Any clue about this?

Hi,

use only the username itself, without ‘@’

Be also aware to use “talk.google.com” as server and “gmail.com” as resouce.

Regards,

Vilson

Hi Vilson and Sergei, I am having the same Issue, I will try now and post back ver soon. Thanks!