Problems with connecting to Facebook XMMP MD5-DIGEST

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.

Hello alexryd,

sorry my English :slight_smile:

I created a chat for Android, the mechanism using X-FACEBOOK-PLATFORM. Using the library as access http://github.com/facebook/facebook-android-sdk. So until a few days ago, works great. Remove the secret from a json object that was attached to the successful response with the access token. The ‘secret’ password in the past as FacebookConnectSASLMechanism class.

Now unfortunately this object json disappears. Is no longer present in the successful response. Maybe facebook has changed something.

How can you get this secret? I tried but does not work with application secret. Could you help me? I’m in trouble :slight_smile:

Thanks

it worked awesome!..but a great prob is the users online are not visible…though i’m receiving their presence “available”…it seems my code is not appropriate…here’s a snap of it…eagerly waiting for reply…

thanks in advance…

public void grabBuddyList()
{
Roster roster = connection.getRoster();
Collection entries = roster.getEntries();

        System.out.println("\n\n" + entries.size() + " buddies:");
        for(RosterEntry r:entries)
        {
        System.out.println(r.getUser());
        }
}

hi everyone! I’m using this api for Processing (java based) and i want to know if there’s allready a simple sollution for this? Processing uses libraries and i’ve allready connected to G-talk. Could someone give me a hint? There’s some code between it for an Eliza bot.

here’s my code:

http://paste2.org/p/1082107

here’s some debug info:

<?xml version="1.0"?>X-FACEBOOK-PLATFORMDIGEST-MD5

cmVhbG09ImNoYXQuZmFjZWJvb2suY29tIixub2 5jZT0iODhFQjBBRkIwMEZBN0M4MkUxNTZGQ0JDMDRFMkJDMTkiLHFvcD0iYXV0aCIsY2hhcnNldD11dG YtOCxhbGdvcml0aG09bWQ1LXNlc3M=

<stream:stream to=“chat.facebook.com” xmlns=“jabber:client” xmlns:stream=“http://etherx.jabber.org/streams” version=“1.0”>

Y2hhcnNldD11dGYtOCx1c2VybmFtZT0ibWFydG lqbm1lIixyZWFsbT0iY2hhdC5mYWNlYm9vay5jb20iLG5vbmNlPSJDRTVDOTYwQ0RBMzM0NjdGMTE4OU FGMzkzRkRCODU1MiIsbmM9MDAwMDAwMDEsY25vbmNlPSJVK1oxb1JyNk9sK3JudzJXZTR0d0hueFMrVG RqNDlXcUV0azZJQWhBIixkaWdlc3QtdXJpPSJ4bXBwL2NoYXQuZmFjZWJvb2suY29tIixtYXhidWY9Nj U1MzYscmVzcG9uc2U9OTY4MWVmOTkwNjUzNTBiNDFkNDQ0YzY0NTkxNjczMTkscW9wPWF1dGgsYXV0aH ppZD0ibWFydGlqbm1lIg==
Hello. How do you do. Please state your problem.b2F860

</stream:stream>
<stream:stream to=“chat.facebook.com” xmlns=“jabber:client” xmlns:stream=“http://etherx.jabber.org/streams” version=“1.0”>

Hi @Kees,

If you can connect to gtalk then you shouldn’t have any issue connecting to facebook using digest-md5. Just make you sure you have a proper facebook user ID (not your email address). You can get your username by logging into facebook and looking under account settings there will be something called “Username”.

try something like

test@chat.facebook.com

password

server should be - chat.facebook.com

port - 5222

i get this:

ASL authentication failed using mechanism DIGEST-MD5:

I’ve allready got a username and inserted this

hello kees…i had this problem just a few days ago…now i have solved it & my app is working too fine!

u dont need SASL md5 for google.U need it only for facebook.here’s the code snippet:

try
{

if(frameName==“Facebook”)
{

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

config = new ConnectionConfiguration(“chat.facebook.com”,5222);
config.setSASLAuthenticationEnabled(true);
config.setRosterLoadedAtLogin (true);
}
if(frameName==“gTalk”)
{
config = new ConnectionConfiguration(“talk.google.com”,5222, “gmail.com”);
config.setSASLAuthenticationEnabled(false);
config.setRosterLoadedAtLogin (true);
}

}

catch(Exception ex)

{ex.printStackTrace();}

////ur code proceeds

if u do ur code in jcreator or netbeans u have to include this jar SASLin ur project.