Problems with connecting to Facebook XMMP MD5-DIGEST

Hi Manuel,

X-FACEBOOK-PLATFORM is a custom SASL mechanims provided by Facebook itself. Take note that in this challenge-response mechanism is under UTF-8 encoding and not the standard way of sending packets of XMPP which is Base64 encoded. Also please take note that you need your account to have permission on it. I will try to use this approach but I guess I need to register first an application to facebook before anything else.

Hello Julian,

thanks for your response! you are right, first you have to register an application on facebook to get started! this is done pretty fast!

I already considered your mentioned points:

  • I have the permission to interact with the fb chat,

  • and the UTF-8 encoding is not a problem, since messaging with MD5-DIGEST authentication already works!

Its more a problem with the smack lib to register this new custom authentication method from FB …I know that I have to write my own SASLMechanism

class to be able to respone to the specific FB behavior. BUT it fails when I want to receive a valid SaslClient from the lib!

EDIT:

looks like it is not possible to register any costum authentication method which is NOT based on something like MD5 etc. -> so I am playing around with SASLAnonymous, where I try to send my special FB responses!

would be cool to hear soon from your experience with fb xmpp connect authentication!

regards,

Manuel

Any luck with supporting the “X-FACEBOOK-PLATFORM” authentication?

Thanks.

yeahh I used the SASLPlainMechanism to implement my own authentication process.

I had quite big problems in the beginning but I could solve it!

you may want to look also on http://forum.developers.facebook.com/viewtopic.php?id=51892

for information

good luck, Askin

Hello Gennady , thanx a bunch for all the help you are sharing on your topics , whatever i’m running out of time & means

i’ve developped a class which is supposed to interact with facebook following what you’ve said , ( I have successfully done the stuff for GTALK) but i really need to come over the facebook challenge , well here is my source code , if you have any notice please keep me up to date guys :slight_smile:

actually , i’ve used the MD5 class given above : mysalsdigestmd5mechanism.class

PLEAASE HELP :slight_smile:

**import org.jivesoftware.smack.RosterEntry; **

import

**import org.jivesoftware.smack.XMPPException; **

import

org.jivesoftware.smack.packet.Message;

public

/**

  • **@param args **

*/

// **TODO Auto-generated method stub **

// peut etre un probleme au niveau des utilisateurs

FacebookChat(

}

{

//FACEBOOK AUTHENTIFICATION

SASLAuthentication.registerSASLMechanism(

ConnectionConfiguration config =

XMPPConnection connection =

connection.connect();

}

// **TODO Auto-generated catch block **

e4.printStackTrace();

}

connection.login(username, password);

}

// **TODO Auto-generated catch block **

e3.printStackTrace();

}

// user name should not contain @chat

// TRUE POUR FACEBOOK , FALSE POUR GTALK , en fait facebook uses MD5 , pas GTALK :wink: plain authentification

// config.setSASLAuthenticationEnabled(true);

connection.connect();

}

// **TODO Auto-generated catch block **

e2.printStackTrace();

}

/* Connect to the XMPP server */

connection.login(username,password);

}

// **TODO Auto-generated catch block **

e1.printStackTrace();

}

/* Login to the IM service */

Chat chat = connection.getChatManager().createChat(destination,

chat.sendMessage(message);

}

// **TODO Auto-generated catch block **

e.printStackTrace();

}

/* Send the message */

connection.disconnect() ;

//Disconnect 8

}

__public __void processMessage(Chat chat,Message message) /*Callback method from MessageListener interface . It is called when a message is received */ ____

{

System.

}

}

Youssef

out.println("Received message: " + message.getBody());

catch (XMPPException e) {

try {

new SimpleTalking());

catch (XMPPException e1) {

try {

catch (XMPPException e2) {

try {

catch (XMPPException e3) {

try {

catch (XMPPException e4) {

try {

new XMPPConnection(config);

new ConnectionConfiguration(“chat.facebook.com”, 5222);

“DIGEST-MD5”, MySASLDigestMD5Mechanism.class);

public static void FacebookChat(String username , String password , String destination , String message )

sender@domain.com,“Password”,Destinator@domain.com,“Yes !! it’s done ;)”);

Best regardss

public static void main(String[] args) {

class SimpleTalking implements MessageListener {



import org.jivesoftware.smack.XMPPConnection;

org.jivesoftware.smack.SASLAuthentication;


import org.jivesoftware.smack.Roster;

import org.jivesoftware.smack.MessageListener;

import org.jivesoftware.smack.ConnectionConfiguration;

import org.jivesoftware.smack.Chat;

import java.io.*;

import java.util.*;

@Askin,

I’m trying to using asmack to use facebook X-FACEBOOK-PLATFORM as authentication, could you please explain how I could accomplish this?

If found a project called fbgc on Google Code that helped me add support for X-FACEBOOK-PLATFORM to my application. Look at the files FacebookConnectSASLMechanism.java and SessionHandlerImpl.java for an example implementation.

Note though that you need both xmpp_login and offline_access permissions for it to work. Took me a few hours to realize…

Could someone please tell me how to generate the secret session key? I tried,

Bundle parameters1 = new Bundle();

parameters1.putString(“api_key”, “77159c8a694c6a7fae3627261cd2e5c5”);

parameters1.putString(“v”, “1.0”);

parameters1.putString(“auth_token”, authenticatedFacebook.getAccessToken());

parameters1.putString(“generate_session_secret”, “1”);

parameters1.putString(“method”,“auth.getSession”);

Bundle parameters1 = new Bundle();

parameters1.putString(“api_key”, “77159c8a694c6a7fae3627261cd2e5c5”);

parameters1.putString(“v”, “1.0”);

parameters1.putString(“auth_token”, authenticatedFacebook.getAccessToken());

parameters1.putString(“generate_session_secret”, “1”);

parameters1.putString(“method”,“auth.getSession”);

But it didn’t work. I know it’s easy, but I’m finding it hard. :S

Please could you post some sample code where you demonstrate fully

the login process? So far the lack of documentation at facebook was really frustrating and

you could help me a lot with a small post. Thx in advance.

Attached is the class that I made for handling the X-FACEBOOK-PLATFORM mechanism. Most of it is borrowed from the fbgc project on Google Code.

Add that class to your application, and then do something like this:

SASLAuthentication.registerSASLMechanism(SASLXFacebookPlatformMechanism.NAME, SASLXFacebookPlatformMechanism.class);
SASLAuthentication.supportSASLMechanism(SASLXFacebookPlatformMechanism.NAME, 0); ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222); XMPPConnection connection = new XMPPConnection(config);
connection.connect();
connection.login(apiKey + "|" + sessionKey, applicationSecret, "Client Name");

Again, note that you need to request both xmpp_login and offline_access permissions, or else the authentication will always fail, even if you do everything else right.
SASLXFacebookPlatformMechanism.java.zip (1881 Bytes)

You don’t generate the session key, it is returned to your application after a successful Facebook Connect authentication. So with the JavaScript SDK you would do something like this:

FB.login(function(response) {
     if (response.session) {
          alert("Session key: " + response.session.session_key);
     }
}, {perms:"xmpp_login,offline_access"});

EDIT: If you’re not using the JavaScript SDK you can extract the session key from the access token. The access token looks like this “something|sessionKey|somethingElse”, so all you need to do is to extract whatever is in between the pipes ( | ). Note though that you need to be using the new Graph API. I have no idea if you can get the correct session key when using the old REST API.

Hey, I’m having a real trouble connecting to Facebook chat via asmack… with smack 3.1 i could connect by using the MySASLMD5DigestMechanism that a member posted here, but since I can’t use javax.security on a Android environment I needed to use the asmack lib, that as a built in SASLM5DigestMechanism. Whenever I try to use it i get a no class found exception… this is my code for connecting

import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.sasl.SASLDigestMD5Mechanism;

/**
*

  • @author Pedro
    */
    public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

SASLAuthentication.registerSASLMechanism(“DIGEST-MD5”, SASLDigestMD5Mechanism.class);
ConnectionConfiguration connConfig = new ConnectionConfiguration(“chat.facebook.com”);

XMPPConnection connection = new XMPPConnection(connConfig);

try {
connection.connect();
connection.login(“BentoElGaton”, “UwishUknew:P”);
} catch (XMPPException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

this is the result of build and run…

run:
Exception in thread “main” java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParser
at org.jivesoftware.smack.Connection.(Connection.java:118)
at org.jivesoftware.smack.ConnectionConfiguration.(ConnectionConfiguration.j ava:73)
at Threads.Main.main(Main.java:30)
Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParser
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
… 3 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

Please help, since I don’t understand anything about security, thanks

I’m working on desktop with the asmack lib…

Well, I found out that to use asmack on a desktop environment you need some classes of the android jdk… But now i’m on android using asmack connected to facebook via DIGEST-MD5 and it work flawlessly… you just need to add the line

SASLAuthentication.registerSASLMechanism(“DIGEST-MD5”, SASLDigestMD5Mechanism.class);

and the mechanism embedded on the asmack does the trick by itself =) no need to fancy code tricks

Has anyone actually gotten this to work on the Android?

I did with asmack…

I think my problem is that my sessions are not persisting between activities, authenticate with facebook in my main activity and then I go and try to xmpp authenticate in another activity.

Did you have to use the git facebook sdk to actually allow offline permissions first?

He said he got it to work with MD-5 not X-Facebook-Platform.

Is yours with X-FACEBOOK-PLATFORM? If so I’d definitely like to see the code…

With MD-5-Digest, it works flawlessly.

I am trying to get it work anyway I can. MD-5 Digest is not working for me at all. I get a request failed every time. im using the 05.07 build of the jar and the code is really straightforward

ConnectionConfiguration config = new ConnectionConfiguration(“chat.facebook.com”, 5222, “chat.facebook.com”);
myConn = new XMPPConnection(config);
config.setSASLAuthenticationEnabled(true);
config.setDebuggerEnabled(true);

myConn.connect();

//username is straight username- no @gmail.com and no @chat.facebook.com

//password is my password

myConn.login(username,password);

Log.i(“XMPP”, myConn.getHost() + “,” + myConn.getServiceName());

Do you guys see anything that I am doing wrong?

I used your file, and I get the challenge but when I construct a response to to the challenge keeps failing, I have set permissions as well. Everything seems ok, but I’m obviously making a mistake somewhere. Can you please help me? I’m coding on java, for android…

A sample application would be really helpful.

Thanks in advance.