69 Replies Latest reply on Aug 26, 2012 10:38 PM by RK

    Problems with connecting to Facebook XMMP MD5-DIGEST

    gsproof Bronze

      Hi,

       

      I was trying to connect to newly added Facebook XMPP service with smack 3.1.0. Facebook XMPP supports MD5-DIGEST, but unfortunately it just didn't work. After long hours I've found that the problem was the way SASLMechanism class creates sasl client, i.e

       

      public void authenticate(String username, String host, String password) throws IOException, XMPPException {

      ...

              //Set the authenticationID as the username, since they must be the same in this case.
              this.authenticationId = username;
      ...       
              sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this);
              authenticate();

      }

       

      The userName is passed as authorizationId parameter. The result was an error: "SASL authentication failed using mechanism DIGEST-MD5".

       

      The fix was to pass null as authorizationId (instead of userName) which sorted the things out and I was able to connect.

       

      sc = Sasl.createSaslClient(mechanisms, null, "xmpp", host, props, this);

       

      Did anyone else faced the same issue?

      Should smack be patched?

       

      Regards,

      Gennady

        • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
          amr88 Bronze

          I've made the recommended change and recompiled the JARs, but I'm still getting this same error when trying to connect to Facebook chat. Would you mind sharing some snippets of code? I think I have everything (server/port/etc) correct, but it's not authenticating.

           

          EDIT: Making the changes in this thread:

           

          http://www.igniterealtime.org/community/thread/35976

           

          and recompiling seems to have fixed my problem. Thanks a ton for this thread!

            • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
              gsproof Bronze

              You are right, I forgot to mention that applied this patch either.

              BTW, pay attention that Sasl.createSaslClient appears in multiple places depending on which athenticate(..) method is called.

               

              Are there plans to make an official release of 3.1.1 , there is a nice number of changes accumulated since 3.1.0?

               

              Gennady.

              • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                Julian Tasis Bronze

                Hi I was trying to connect to facebook via their xmpp server. I also encountered the same errors you guys have. Based on your exchanges here it seems that you already have fixed the problem. Can you help me out with it also? Did you recompile smack library setting the username on authenticate method to null? I just got confused. By the way this is how I'm trying to connect to facebook, based on the thread you've provided there are times that we need to provided @domain on the username. How about in facebook case?

                 

                 

                 

                org.jivesoftware.smack.ConnectionConfiguration configuration = new org.jivesoftware.smack.ConnectionConfiguration("chat.facebook.com", 5222);
                org.jivesoftware.smack.XMPPConnection connection = new org.jivesoftware.smack.XMPPConnection(configuration);
                connection.connect();
                connection.login("username", "password");
                or should I used
                connection.login("username@chat.facebook.com", "password");
                Thanks guys.
                     
                  • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                    gsproof Bronze

                    You coud take the sources from http://svn.igniterealtime.org/svn/repos/smack/trunk

                    modify SASLMechanism class:  fix all Sasl.createSaslClient calls to pass 2nd param as null instead of username

                    and build your own copy of the library (with ant from build directory)

                     

                    The problem is that SASLMechanism is the base class for all mechanisms (plain, cramMD5, etc.) and I am not sure how this change will affect them. Futhermore I am not sure that passing username is wrong at all and probably it's a bug of facebook xmpp implementation.

                     

                    So the other solution is to provide your own compact DigestMD5 implementation that extends SASLMechanism, but overrides authenticate() methods. I am attaching such an implementation. Then you can call it as :

                     

                    SASLAuthentication.registerSASLMechanism("DIGEST-MD5", MySASLDigestMD5Mechanism.class);
                    ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222);
                    connection = new XMPPConnection(config);

                    connection.connect();
                    connection.login(userName, pwd);   // user name should not contain @chat....

                     

                     

                    Gennady

                      • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                        Julian Tasis Bronze

                        Thanks for the reply. I'll try to use it.  I will also try to modify SASLDigestMD5Mechanism for this purpose. I actually thought that the reason why facebook is returning failure was because of wrong base64 encoding of challenge - response on login.

                         

                         

                        Edit:2

                          Got it working thanks for the sample class.

                         

                        Edit:1

                          I tried your solution but still getting the failed authentication it seems I need to check out on SVN first. It is quite a while since I updated my sources.

                        • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                          Askin Bronze

                          Thanks for the patch it works fine for me in case of using DIGEST-MD5 authentication!

                          Unfortunatelly in our solution we need to connect to facebook via the FB-connect solution or so called X-FACEBOOK-PLATFORM mechanism

                          (for more info look: http://wiki.developers.facebook.com/index.php/Integrating_with_Facebook_Chat)

                           

                          So this is a new authentication method and I try to register this auth method like mentioned in the smack documentation with

                          registerSASLMechanism(String, Class)

                          supportSASLMechanism(String, int)

                           

                          But I get a null pointer exception from the Sasl.createSaslClient(mechanisms, null, "xmpp", hostname, props, this); call in the SASLMechanism.authentication() method, because the X-FACEBOOK-PLATFORM mechanism is not in the "Securtiy Provider" list, like DIGEST-MD5.

                           

                          Do you have any help why the registration doesnt work or what I can do to get the facebook authentication mechanism to run???

                          THANKS a lot in advance!

                          best regards,

                          Manuel

                           

                          PS: here are the last lines from the stack trace:

                           

                          java.lang.NullPointerException
                              at org.jivesoftware.smack.sasl.SASLMechanism.authenticate(SASLMechanism.java:117)
                              at communityConnections.MySASLFacebookMechanism.authenticate(MySASLFacebookMechani sm.java:34)
                              at communityConnections.MySASLFacebookMechanism.authenticate(MySASLFacebookMechani sm.java:45)
                              at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java: 308)
                              at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:395)
                              at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:349)

                          • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                            yghalem Bronze

                            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 :-)

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

                            PLEAASE HELP :-)

                             

                             

                            import java.util.*;

                             

                            import java.io.*;

                             

                             

                            import org.jivesoftware.smack.Chat;

                             

                            import org.jivesoftware.smack.ConnectionConfiguration;

                             

                            import org.jivesoftware.smack.MessageListener;

                             

                            import org.jivesoftware.smack.Roster;

                             

                            import org.jivesoftware.smack.RosterEntry;

                            import

                             

                             

                             

                             

                             

                            org.jivesoftware.smack.SASLAuthentication;

                             

                            import org.jivesoftware.smack.XMPPConnection;

                             

                            import org.jivesoftware.smack.XMPPException;

                            import

                             

                             

                             

                             

                             

                            org.jivesoftware.smack.packet.Message;

                             

                              

                             

                            public

                             

                             

                             

                             

                             

                            class SimpleTalking implements MessageListener {

                             

                             

                            /**

                             

                             

                             

                            * @param args

                             

                             

                             

                            */

                             

                             

                             

                             

                             

                            public static void main(String[] args) {

                             

                            // TODO Auto-generated method stub

                             

                             

                             

                            // peut etre un probleme au niveau des utilisateurs

                            FacebookChat(

                             

                             

                            sender@domain.com,"Password",Destinator@domain.com,"Yes !! it's done ;)");

                            }

                             

                             

                             

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

                            {

                             

                             

                             

                            //FACEBOOK AUTHENTIFICATION

                             

                            SASLAuthentication.registerSASLMechanism(

                             

                             

                            "DIGEST-MD5", MySASLDigestMD5Mechanism.class);

                            ConnectionConfiguration config =

                            new ConnectionConfiguration("chat.facebook.com", 5222);

                            XMPPConnection connection =

                            new XMPPConnection(config);

                             

                             

                            try {

                            connection.connect();

                            }

                            catch (XMPPException e4) {

                             

                            // TODO Auto-generated catch block

                            e4.printStackTrace();

                            }

                             

                             

                             

                            try {

                            connection.login(username, password);

                            }

                            catch (XMPPException e3) {

                             

                            // 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 ;-) plain authentification

                             

                             

                             

                            // config.setSASLAuthenticationEnabled(true);

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                            try {

                            connection.connect();

                            }

                            catch (XMPPException e2) {

                             

                            // TODO Auto-generated catch block

                            e2.printStackTrace();

                            }

                             

                             

                            /* Connect to the XMPP server */

                             

                             

                             

                            try {

                            connection.login(username,password);

                            }

                            catch (XMPPException e1) {

                             

                            // TODO Auto-generated catch block

                            e1.printStackTrace();

                            }

                             

                             

                            /* Login to the IM service */

                             

                              

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

                             

                             

                            new SimpleTalking());

                             

                            try {

                            chat.sendMessage(message);

                            }

                            catch (XMPPException e) {

                             

                            // 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.

                             

                             

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

                            }

                             

                             

                             

                            }

                             

                            Youssef

                              

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                            Best regardss

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                             

                            • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                              Md.Abdul Munim Dibosh Bronze

                              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<RosterEntry> entries = roster.getEntries();
                                     
                                          System.out.println("\n\n" + entries.size() + " buddies:");
                                          for(RosterEntry r:entries)
                                          {
                                          System.out.println(r.getUser());
                                          }
                                  }

                              • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                leolee Bronze

                                SASL authentication DIGEST-MD5 failed: not-authorized:

                                 

                                hi, I'm trying to using your file. but : SASL authentication DIGEST-MD5 failed: not-authorized.

                                 

                                my code:

                                 

                                 

                                SASLAuthentication.registerSASLMechanism("DIGEST-MD5", MySASLDigestMD5Mechanism1.class);

                                              SASLAuthentication.supportSASLMechanism("DIGEST-MD5", 0);

                                             

                                                    config = new ConnectionConfiguration("chat.facebook.com", 5222, "chat.facebook.com");

                                        config.setSASLAuthenticationEnabled(true);

                                        config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);

                                 

                                config.setSendPresence(false);

                                       

                                        config.setSocketFactory(proxy.getSocketFactory());

                                        //

                                        conn = new XMPPConnection(config);

                                        try {

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

                                                              conn.connect();

                                                  conn.addConnectionListener(this);

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

                                                  conn.login(username, pd, "leolee.com");

                                                    } catch (XMPPException e) {

                                                              // TODO Auto-generated catch block

                                                              e.printStackTrace();

                                                    }

                                 

                                 

                                thank you.

                                • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                  Solaiemes Bronze

                                  Hi there!!

                                   

                                  I'm quite new at this. I downloaded your file and I am get an error with your las sentence:

                                   

                                  getSASLAuthentication().send(stanza.toString());

                                   

                                  It's all the time saying that the method send is not applicable for the type String. What is wrong with this???

                                  I just want to try and connect with FB and I see that many of those who have used your file now can connect properly.

                                   

                                  Thanks in advance.

                                  • Problems with connecting to Facebook XMMP MD5-DIGEST
                                    Jerry Magill Bronze

                                    I used your code but it no longer worked so I patched it at little and am returning it to the community. It works like a charm for facebook.

                                     

                                    import java.io.IOException;

                                    import java.util.HashMap;

                                    import javax.security.auth.callback.CallbackHandler;

                                    import javax.security.sasl.Sasl;

                                    import org.jivesoftware.smack.SASLAuthentication;

                                    import org.jivesoftware.smack.XMPPException;

                                    import org.jivesoftware.smack.sasl.SASLMechanism;

                                    import org.jivesoftware.smack.packet.Packet;

                                    import org.jivesoftware.smack.util.Base64;

                                     

                                    public class MySASLDigestMD5Mechanism extends SASLMechanism

                                    {

                                     

                                        public MySASLDigestMD5Mechanism(SASLAuthentication saslAuthentication)

                                        {

                                            super(saslAuthentication);

                                        }

                                     

                                        protected void authenticate()

                                            throws IOException, XMPPException

                                        {

                                            String mechanisms[] = {

                                                getName()

                                            };

                                            java.util.Map props = new HashMap();

                                            sc = Sasl.createSaslClient(mechanisms, null, "xmpp", hostname, props, this);

                                            super.authenticate();

                                        }

                                     

                                        public void authenticate(String username, String host, String password)

                                            throws IOException, XMPPException

                                        {

                                            authenticationId = username;

                                            this.password = password;

                                            hostname = host;

                                            String mechanisms[] = {

                                                getName()

                                            };

                                            java.util.Map props = new HashMap();

                                            sc = Sasl.createSaslClient(mechanisms, null, "xmpp", host, props, this);

                                            super.authenticate();

                                        }

                                     

                                        public void authenticate(String username, String host, CallbackHandler cbh)

                                            throws IOException, XMPPException

                                        {

                                            String mechanisms[] = {

                                                getName()

                                            };

                                            java.util.Map props = new HashMap();

                                            sc = Sasl.createSaslClient(mechanisms, null, "xmpp", host, props, cbh);

                                            super.authenticate();

                                        }

                                     

                                        protected String getName()

                                        {

                                            return "DIGEST-MD5";

                                        }

                                     

                                        public void challengeReceived(String challenge)

                                            throws IOException

                                        {

                                            //StringBuilder stanza = new StringBuilder();

                                            byte response[];

                                            if(challenge != null)

                                                response = sc.evaluateChallenge(Base64.decode(challenge));

                                            else

                                                //response = sc.evaluateChallenge(null);

                                                response = sc.evaluateChallenge(new byte[0]);

                                            //String authenticationText = "";

                                            Packet responseStanza;

                                            //if(response != null)

                                            //{

                                                //authenticationText = Base64.encodeBytes(response, 8);

                                                //if(authenticationText.equals(""))

                                                    //authenticationText = "=";

                                               

                                                if (response == null){

                                                    responseStanza = new Response();

                                                } else {

                                                    responseStanza = new Response(Base64.encodeBytes(response,Base64.DONT_BREAK_LINES));   

                                                }

                                            //}

                                            //stanza.append("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");

                                            //stanza.append(authenticationText);

                                            //stanza.append("</response>");

                                            //getSASLAuthentication().send(stanza.toString());

                                            getSASLAuthentication().send(responseStanza);

                                        }

                                    }

                                     

                                     

                                     

                                     

                                     

                                     

                                    It is then called thus from the JabberSmackAPI:

                                     

                                        public void login(String userName, String password) throws XMPPException

                                        {       

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

                                            ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com",5222);

                                     

                                            config.setSASLAuthenticationEnabled(true);

                                            config.setRosterLoadedAtLogin (true);

                                     

                                            connection = new XMPPConnection(config);

                                            connection.connect();

                                            connection.login(userName, password);

                                        }

                              • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                Hades Bronze

                                Askin,

                                 

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

                                  • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                    alexryd Bronze

                                    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...

                                      • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                        Hades Bronze

                                        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

                                          • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                            alexryd Bronze

                                            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.

                                          • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                            Kostas Papagiannopoulos Bronze

                                            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.

                                              • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                alexryd Bronze

                                                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.

                                                  • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                    Hades Bronze

                                                    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.

                                                    • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                      lespaul Bronze

                                                      Hello alexryd,

                                                       

                                                      sorry my English :-)

                                                       

                                                      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 :-)

                                                       

                                                      Thanks

                                                      • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                        Shai Berger Bronze

                                                        Hi alexryd and everyone,

                                                         

                                                        Since this post was made, it seems Facebook have changed their API somewhat; this thread, and your post in particular, have been very helpful for me in getting things to work, so I'm contributing back an updated solution which works for me.

                                                         

                                                        The attached source is a new version of the SASL Mechanism for Facebook Platform; it is simpler than the earlier version, as the sig is no longer required.

                                                         

                                                        The usage is similar to the previous version, but again simpler: You don't need the session key. The one thing that is slightly more complex is that, instead of the application secret, you now use an access token that you need to get from Facebook (see http://developers.facebook.com/docs/authentication/). Facebook (in https://developers.facebook.com/docs/chat/) recommend you use the client flow to get the token, and that's what I did; the server flow is supposed to yield a similar token, so it should work just as well.

                                                         

                                                        The new usage code looks like:

                                                         

                                                        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, accessToken, "Client Name"); // Client name optional
                                                        

                                                         

                                                        Hope this helps,

                                                         

                                                        Shai.

                                                    • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                      vu3mmg Bronze

                                                      HI ,

                                                      I have a doubt with X-FACEBOOK.

                                                      I  am confused with the login behaviour of the same .Is it possible to write  applications such as chat bots  with this mechanism .What is the relation to session key and chat  Can a chat  application using this mechanim, send message to a face book user .

                                                      regards

                                                      mahesh

                                                  • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                    Pedro Bronze

                                                    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.<clinit>(Connection.java:118)
                                                            at org.jivesoftware.smack.ConnectionConfiguration.<init>(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...

                                                    • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                      Kees Bokhoven Bronze

                                                      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"?><stream:stream id="AE50B5AB" from="chat.facebook.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0" xml:lang="en"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-FACEBOOK-PLATFORM</mechan ism><mechanism>DIGEST-MD5</mechanism></mechanisms></stream:features>
                                                      <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cmVhbG09ImNoYXQuZmFjZWJvb2suY29tIixub2 5jZT0iODhFQjBBRkIwMEZBN0M4MkUxNTZGQ0JDMDRFMkJDMTkiLHFvcD0iYXV0aCIsY2hhcnNldD11dG YtOCxhbGdvcml0aG09bWQ1LXNlc3M=</challenge>
                                                      <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>

                                                       

                                                       

                                                      <stream:stream to="chat.facebook.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
                                                      <auth mechanism="DIGEST-MD5" xmlns="urn:ietf:params:xml:ns:xmpp-sasl"></auth>
                                                      <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">Y2hhcnNldD11dGYtOCx1c2VybmFtZT0ibWFydG lqbm1lIixyZWFsbT0iY2hhdC5mYWNlYm9vay5jb20iLG5vbmNlPSJDRTVDOTYwQ0RBMzM0NjdGMTE4OU FGMzkzRkRCODU1MiIsbmM9MDAwMDAwMDEsY25vbmNlPSJVK1oxb1JyNk9sK3JudzJXZTR0d0hueFMrVG RqNDlXcUV0azZJQWhBIixkaWdlc3QtdXJpPSJ4bXBwL2NoYXQuZmFjZWJvb2suY29tIixtYXhidWY9Nj U1MzYscmVzcG9uc2U9OTY4MWVmOTkwNjUzNTBiNDFkNDQ0YzY0NTkxNjczMTkscW9wPWF1dGgsYXV0aH ppZD0ibWFydGlqbm1lIg==</response>
                                                      <message id="wLkbR-0" to="ikillbombs@gmail.com" type="chat"><body>Hello. How do you do.  Please state your problem.</body><thread>b2F860</thread></message>
                                                      <presence id="wLkbR-1" type="unavailable"></presence>
                                                      </stream:stream>
                                                      <stream:stream to="chat.facebook.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">

                                                      • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                        Md.Abdul Munim Dibosh Bronze

                                                        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.

                                                        • Problems with connecting to Facebook XMMP MD5-DIGEST
                                                          arun Bronze

                                                          Hi,

                                                          I am getting following error

                                                          java.lang.NullPointerException

                                                              at org.jivesoftware.smack.sasl.SASLMechanism.authenticate(SASLMechanism.java:117)

                                                              at MySASLDigestMD5Mechanism.authenticate(MySASLDigestMD5Mechanism.java:43)

                                                              at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java: 308)

                                                              at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:395)

                                                              at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:349)

                                                           

                                                          my code is

                                                          SASLAuthentication.registerSASLMechanism("DIGEST-MD5",

                                                                             MySASLDigestMD5Mechanism. class);

                                                               ConnectionConfiguration  config =   new ConnectionConfiguration("chat.facebook.com",5222);

                                                                    config.setSASLAuthenticationEnabled(true);

                                                                     config.setRosterLoadedAtLogin (true);

                                                                   

                                                                     XMPPConnection connection = new XMPPConnection(config);

                                                           

                                                                     connection.connect();

                                                                     System.out.println(connection.getServiceName());

                                                                     connection.login("xxxxxxxxx", "xxxxxx");

                                                           

                                                          How to do it, Please explain, Its urgent....

                                                          • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                            abhi902 Bronze

                                                            Hello, I'm just an amateur with smack api, and I'm trying hard to connect to facebook chat using x-facebook platform.

                                                             

                                                            I am using the custom SASL mechanism class for facebook authentication described above. But getting errors, actually I do not know exactly how to perform this.

                                                             

                                                             

                                                            public class SASLXFacebookPlatformMechanism extends SASLMechanism {
                                                                public static final String NAME = "X-FACEBOOK-PLATFORM";
                                                             
                                                             
                                                                private String apiKey = "";
                                                                private String applicationSecret = "";
                                                                private String sessionKey = "";
                                                             
                                                             
                                                                /**
                                                                 * Constructor.
                                                                 */
                                                                public SASLXFacebookPlatformMechanism1(SASLAuthentication saslAuthentication) {
                                                                    super(saslAuthentication);
                                                                }
                                                             
                                                                @Override
                                                                protected void authenticate() throws IOException, XMPPException {
                                                                    StringBuilder stanza = new StringBuilder();
                                                                    stanza.append("<auth mechanism=\"").append(getName());
                                                                    stanza.append("\" xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
                                                                    stanza.append("</auth>");
                                                             
                                                                    // Send the authentication to the server
                                                                    getSASLAuthentication().send(stanza.toString());
                                                                }
                                                             
                                                                @Override
                                                                public void authenticate(String apiKeyAndSessionKey, String host, String applicationSecret) throws IOException, XMPPException {
                                                                    if (apiKeyAndSessionKey == null || applicationSecret == null)
                                                                        throw new IllegalArgumentException("Invalid parameters");
                                                             
                                                                    String[] keyArray = apiKeyAndSessionKey.split("\\|", 2);
                                                                    if (keyArray.length < 2)
                                                                        throw new IllegalArgumentException("API key or session key is not present");
                                                             
                                                                    this.apiKey = keyArray[0];
                                                                    this.applicationSecret = applicationSecret;
                                                                    this.sessionKey = keyArray[1];
                                                             
                                                                    this.authenticationId = sessionKey;
                                                                    this.password = applicationSecret;
                                                                    this.hostname = host;
                                                             
                                                                    String[] mechanisms = { "DIGEST-MD5" };
                                                                    Map<String, String> props = new HashMap<String, String>();
                                                                    this.sc = Sasl.createSaslClient(mechanisms, null, "xmpp", host, props, this);
                                                                    authenticate();
                                                                }
                                                             
                                                                @Override
                                                                public void authenticate(String username, String host, CallbackHandler cbh) throws IOException, XMPPException {
                                                                    String[] mechanisms = { "DIGEST-MD5" };
                                                                    Map<String, String> props = new HashMap<String, String>();
                                                                    this.sc = Sasl.createSaslClient(mechanisms, null, "xmpp", host, props, cbh);
                                                                    authenticate();
                                                                }
                                                             
                                                                @Override
                                                                protected String getName() {
                                                                    return NAME;
                                                                }
                                                             
                                                                @Override
                                                                public void challengeReceived(String challenge) throws IOException {
                                                                    StringBuilder stanza = new StringBuilder();
                                                                    byte[] response = null;
                                                             
                                                                    if (challenge != null) {
                                                                        String decodedChallenge = new String(Base64.decode(challenge));
                                                                        Map<String, String> parameters = getQueryMap(decodedChallenge);
                                                             
                                                                        String version = "1.0";
                                                                        String nonce = parameters.get("nonce");
                                                                        String method = parameters.get("method");
                                                             
                                                                        long callId = new GregorianCalendar().getTimeInMillis() / 1000L;
                                                             
                                                                        String sig = "api_key=" + apiKey
                                                                                        + "call_id=" + callId
                                                                                        + "method=" + method
                                                                                        + "nonce=" + nonce
                                                                                        + "session_key=" + sessionKey
                                                                                        + "v=" + version
                                                                                        + applicationSecret;
                                                             
                                                                        try {
                                                                            sig = md5(sig);
                                                                        }
                                                                        catch (NoSuchAlgorithmException e) {
                                                                            throw new IllegalStateException(e);
                                                                        }
                                                             
                                                                        String composedResponse = "api_key=" + URLEncoder.encode(apiKey, "utf-8")
                                                                                                    + "&call_id=" + callId
                                                                                                    + "&method=" + URLEncoder.encode(method, "utf-8")
                                                                                                    + "&nonce=" + URLEncoder.encode(nonce, "utf-8")
                                                                                                    + "&session_key=" + URLEncoder.encode(sessionKey, "utf-8")
                                                                                                    + "&v=" + URLEncoder.encode(version, "utf-8")
                                                                                                    + "&sig=" + URLEncoder.encode(sig, "utf-8");
                                                             
                                                                        response = composedResponse.getBytes("utf-8");
                                                                    }
                                                             
                                                                    String authenticationText = "";
                                                             
                                                                    if (response != null)
                                                                        authenticationText = Base64.encodeBytes(response, Base64.DONT_BREAK_LINES);
                                                             
                                                                    stanza.append("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
                                                                    stanza.append(authenticationText);
                                                                    stanza.append("</response>");
                                                             
                                                                    // Send the authentication to the server
                                                                    getSASLAuthentication().send(stanza.toString());
                                                                }
                                                             
                                                                private Map<String, String> getQueryMap(String query) {
                                                                    Map<String, String> map = new HashMap<String, String>();
                                                                    String[] params = query.split("\\&");
                                                             
                                                                    for (String param : params) {
                                                                        String[] fields = param.split("=", 2);
                                                                        map.put(fields[0], (fields.length > 1 ? fields[1] : null));
                                                                    }
                                                             
                                                                    return map;
                                                                }
                                                             
                                                                private String md5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
                                                                    MessageDigest md = MessageDigest.getInstance("MD5");
                                                                    md.update(text.getBytes("utf-8"), 0, text.length());
                                                                    return convertToHex(md.digest());
                                                                }
                                                             
                                                                private String convertToHex(byte[] data) {
                                                                    StringBuilder buf = new StringBuilder();
                                                                    int len = data.length;
                                                             
                                                                    for (int i = 0; i < len; i++) {
                                                                        int halfByte = (data[i] >>> 4) & 0xF;
                                                                        int twoHalfs = 0;
                                                             
                                                                        do {
                                                                            if (0 <= halfByte && halfByte <= 9)
                                                                                buf.append((char) ('0' + halfByte));
                                                                            else
                                                                                buf.append((char) ('a' + halfByte - 10));
                                                                            halfByte = data[i] & 0xF;
                                                                        }
                                                                        while (twoHalfs++ < 1);
                                                                    }
                                                             
                                                                    return buf.toString();
                                                                }
                                                            }
                                                            

                                                             

                                                            So now I have this class, but I don't know where I am doing wrong, may be I'm calling it in wrong manner, here is how I made use of this class.

                                                             

                                                             

                                                            ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222);
                                                            config.setSASLAuthenticationEnabled(true);
                                                            config.setDebuggerEnabled(true);
                                                             
                                                            SASLAuthentication.registerSASLMechanism(SASLXFacebookPlatformMechanism.NAME, SASLXFacebookPlatformMechanism.class);
                                                            SASLAuthentication.supportSASLMechanism(SASLXFacebookPlatformMechanism.NAME, 0); 
                                                             
                                                            XMPPConnection connection = new XMPPConnection(config);
                                                            try {
                                                                connection.connect();
                                                            } catch (XMPPException ex) {
                                                                Logger.getLogger(FB.class.getName()).log(Level.SEVERE, null, ex);
                                                            }
                                                            SASLXFacebookPlatformMechanism1 mech=new SASLXFacebookPlatformMechanism1(connection.getSASLAuthentication());
                                                            try {
                                                                mech.authenticate();
                                                            } catch (IOException ex) {
                                                                Logger.getLogger(FB.class.getName()).log(Level.SEVERE, null, ex);
                                                            } catch (XMPPException ex) {
                                                                Logger.getLogger(FB.class.getName()).log(Level.SEVERE, null, ex);
                                                            }
                                                            

                                                            When I execute this code, I get a NullPointerException

                                                             

                                                             

                                                            java.lang.NullPointerException
                                                                at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:514)
                                                                at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:296)
                                                                at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)
                                                                at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)
                                                            
                                                            • Problems with connecting to Facebook XMMP MD5-DIGEST
                                                              Md.Abdul Munim Dibosh Bronze

                                                              Here's my complete solution for newbies.Both google & facebook implementation.Implemented using Thread.Also includes the MD5 checksum class.So I think it's pretty much to get someone started.

                                                              http://fbserver.99k.org/smack_google_facebook.rar

                                                               

                                                              Regards-

                                                              Dibosh

                                                                • Problems with connecting to Facebook XMMP MD5-DIGEST
                                                                  abhi902 Bronze

                                                                  Thanks for your reply. I have got my program working now, but I have problem in getting the correct access key for a user.

                                                                   

                                                                  Although I haven't built any program for authorizing my app. Presently I am just trying to authenticate my app by feeding in some codes provided on http://developers.facebook.com/docs/authentication/ in the address bar of my browser.

                                                                   

                                                                  I am facing following problems:

                                                                   

                                                                  Firstly, I cannot understand that I am building a native desktop app, not a web app so why do I need to give a canvas page, the code to authenticate given in facebook documentation in link given above also require a redirect link to a canvas page. Although, I have created a simple html page and hosted on a server to get proceeded but can you tell me is it necessary or there is any other way around for a native app that do not require a canvas page.

                                                                   

                                                                  Secondly, I proceed as given below, i enter these in address bar and proceed:

                                                                  1) https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_UR L&scope=email,read_stream

                                                                   

                                                                  2) After user presses allow then this appears in my address bar

                                                                  http://YOUR_URL?code=A_CODE_GENERATED_BY_SERVER

                                                                   

                                                                  3) But when I use this CODE in following link

                                                                  https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&redirect_uri =YOUR_URL&client_secret=YOUR_APP_SECRET&code=THE_CODE_FROM_ABOVE

                                                                   

                                                                  I get this error:

                                                                  {
                                                                     "error": {
                                                                        "type": "OAuthException",
                                                                        "message": "Error validating verification code."
                                                                     }
                                                                  }

                                                                   

                                                                  instead of getting a access token. Can you please tell me what is the problem?

                                                                    • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                                      Md.Abdul Munim Dibosh Bronze

                                                                      As far as I told if you use smack & java for your desktop app then

                                                                      there's no need to do this on your own.All these authentication is

                                                                      already done inside the smack api.So why do you bother about writing

                                                                      native codes?I just understand this!And I have given a snippet already

                                                                      That's enough.You just need to dive into smack API more & start

                                                                      handling your UI to respond as a chat program.

                                                                        • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                                          sofiane Bronze

                                                                          Hi,

                                                                          after using the code that you have posted up; i've got an error message

                                                                           

                                                                          SASL authentication DIGEST-MD5 failed: not-authorized:

                                                                              at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java: 337)

                                                                              at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203)

                                                                              at org.jivesoftware.smack.Connection.login(Connection.java:348)

                                                                              at Facebook.login(Facebook.java:46)

                                                                              at Facebook.main(Facebook.java:16)

                                                                           

                                                                          any help ??!!!!

                                                                            • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                                              Md.Abdul Munim Dibosh Bronze

                                                                              I just ran that code again & found everything fine.Did you added the class successfully?If you have problem with the class try to include this Jar in your classpath instead: http://fbserver.99k.org/SASL.jar

                                                                                • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                                                  sofiane Bronze

                                                                                  Hi

                                                                                   

                                                                                  now i've got this error message :

                                                                                   

                                                                                  connected to facebook

                                                                                  Exception in thread "Smack Packet Reader (0)" java.lang.NoSuchMethodError: org.jivesoftware.smack.SASLAuthentication.send(Ljava/lang/String;)V

                                                                                      at MySASLDigestMD5Mechanism.challengeReceived(MySASLDigestMD5Mechanism.java:80)

                                                                                      at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication. java:514)

                                                                                      at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:296)

                                                                                      at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)

                                                                                      at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)

                                                                                  No response from the server.:

                                                                                      at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication .java:73)

                                                                                      at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java: 352)

                                                                                      at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203)

                                                                                      at org.jivesoftware.smack.Connection.login(Connection.java:348)

                                                                                      at Facebook.login(Facebook.java:45)

                                                                                      at Facebook.main(Facebook.java:15)

                                                                                   

                                                                                  here is my code

                                                                                   

                                                                                   

                                                                                  import org.jivesoftware.smack.ConnectionConfiguration;

                                                                                  import org.jivesoftware.smack.SASLAuthentication;

                                                                                  import org.jivesoftware.smack.XMPPConnection;

                                                                                  import org.jivesoftware.smack.XMPPException;

                                                                                   

                                                                                   

                                                                                  public class Facebook {

                                                                                   

                                                                                      /**

                                                                                       * @param args

                                                                                       */

                                                                                      public static void main(String[] args) {

                                                                                          // TODO Auto-generated method stub

                                                                                          try {

                                                                                              login("user@yahoo.com", "pass");

                                                                                          } catch (XMPPException e) {

                                                                                              // TODO Auto-generated catch block

                                                                                              e.printStackTrace();

                                                                                          }

                                                                                   

                                                                                   

                                                                                      }

                                                                                   

                                                                                      public static void login(String userName, String password) throws XMPPException

                                                                                   

                                                                                      {      

                                                                                   

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

                                                                                          //((SASLAuthentication) ss).registerSASLMechanism("DIGEST-MD5",MySASLDigestMD5Mechanism.class);

                                                                                   

                                                                                          ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com",5222);

                                                                                   

                                                                                   

                                                                                   

                                                                                          config.setSASLAuthenticationEnabled(true);

                                                                                   

                                                                                          config.setRosterLoadedAtLogin (true);

                                                                                   

                                                                                   

                                                                                   

                                                                                         XMPPConnection connection = new XMPPConnection(config);

                                                                                   

                                                                                          connection.connect();

                                                                                          System.out.print("connected to facebook\n");

                                                                                          connection.login(userName, password);

                                                                                          System.out.print("logged to facebook\n");

                                                                                   

                                                                                      }

                                                                                   

                                                                                  }

                                                                                   

                                                                                   

                                                                                  nb: in your Zip file a "chatFrame" class is missing , that's  why i 've rewrite it without this class

                                                                                   

                                                                                  thnx

                                                                                    • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                                                      Md.Abdul Munim Dibosh Bronze

                                                                                      u r trying to enter facebook so why there is user@yahoo.com???I forgot

                                                                                      to tell one thing you can not enter facebook from smack using your

                                                                                      mail id.You must have an username in facebook.If you dont have create

                                                                                      one from your facebook account section.And enter the username in ur

                                                                                      app;this time it must run!

                                                                                      And one thing sometimes smack fails to connect in that case re-run ur app.

                                                                                        • Re: Problems with connecting to Facebook XMMP MD5-DIGEST
                                                                                          Satish Sharma Bronze

                                                                                          event

                                                                                          hi wvwn i am new to samck api

                                                                                          and trying to connect to facebook and followed your steps mentioned above but got the following error

                                                                                           

                                                                                          connected to facebook

                                                                                          Exception in thread "Smack Packet Reader (0)" java.lang.NoSuchMethodError: org.j

                                                                                          ivesoftware.smack.SASLAuthentication.send(Ljava/lang/String;)V

                                                                                                  at MySASLDigestMD5Mechanism.challengeReceived(MySASLDigestMD5Mechanism.j

                                                                                          ava:80)

                                                                                                  at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthe

                                                                                          ntication.java:514)

                                                                                                  at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:29

                                                                                          6)

                                                                                                  at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)

                                                                                                  at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)

                                                                                          No response from the server.:

                                                                                                  at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuth

                                                                                          entication.java:73)

                                                                                                  at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentica

                                                                                          tion.java:352)

                                                                                                  at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203)

                                                                                                  at org.jivesoftware.smack.Connection.login(Connection.java:348)

                                                                                                  at Facebook.login(Facebook.java:93)

                                                                                                  at Facebook.main(Facebook.java:33)

                                                                                           

                                                                                          D:\try fb>

                                                                                           

                                                                                          my code is

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                          import org.jivesoftware.smack.ConnectionConfiguration;

                                                                                           

                                                                                          import org.jivesoftware.smack.SASLAuthentication;

                                                                                           

                                                                                          import org.jivesoftware.smack.XMPPConnection;

                                                                                           

                                                                                          import org.jivesoftware.smack.XMPPException;

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                          public class Facebook {

                                                                                           

                                                                                           

                                                                                           

                                                                                              /**

                                                                                           

                                                                                               * @param args

                                                                                           

                                                                                               */

                                                                                           

                                                                                              public static void main(String[] args) {

                                                                                           

                                                                                                  // TODO Auto-generated method stub

                                                                                           

                                                                                                  try {

                                                                                           

                                                                                                   login("facebokusername", "fbpasword");

                                                                                           

                                                                                                  } catch (XMPPException e) {

                                                                                           

                                                                                                      // TODO Auto-generated catch block

                                                                                           

                                                                                                      e.printStackTrace();

                                                                                           

                                                                                                  }

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                              }

                                                                                           

                                                                                           

                                                                                           

                                                                                              public static void login(String userName, String password) throws XMPPException

                                                                                           

                                                                                           

                                                                                           

                                                                                              {     

                                                                                           

                                                                                           

                                                                                           

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

                                                                                           

                                                                                                  //((SASLAuthentication) ss).registerSASLMechanism("DIGEST-MD5",MySASLDigestMD5Mechanism.class);

                                                                                           

                                                                                           

                                                                                           

                                                                                                  ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com",5222);

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                                  config.setSASLAuthenticationEnabled(true);

                                                                                           

                                                                                           

                                                                                           

                                                                                                  config.setRosterLoadedAtLogin (true);

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                           

                                                                                                 XMPPConnection connection = new XMPPConnection(config);

                                                                                           

                                                                                           

                                                                                           

                                                                                                  connection.connect();

                                                                                           

                                                                                                  System.out.print("connected to facebook\n");

                                                                                           

                                                                                                  connection.login(userName, password);

                                                                                           

                                                                                                  System.out.print("logged to facebook\n");

                                                                                           

                                                                                           

                                                                                           

                                                                                              }

                                                                                           

                                                                                           

                                                                                           

                                                                                          }

                                                                                           

                                                                                           

                                                                                           

                                                                                          i have used the facebook username and the password for the same but could not log in to accoutn and ended up with the above error

                                                                                          evne i tried your zip files but have the same error for them, after removing the chatframe code fragment

                                                                                          please help...........

                                                                                      • Problems with connecting to Facebook XMMP MD5-DIGEST
                                                                                        RK Bronze

                                                                                        Hi Abdul,

                                                                                        I have tried importing the SASL.jar in my build path. However, I still have issues with

                                                                                        1. MySASLDigestMD5Mechanism cannot be resolved to a type

                                                                                        2. faceBook cannot be resolved to a type

                                                                                        3. chatFrame cannot be resolved to a type

                                                                              • Problems with connecting to Facebook XMMP MD5-DIGEST
                                                                                KwapFace Bronze

                                                                                So to reply to the ORIGINAL discussion at hand, for those who are NOT trying to do X-Facebook, but just DIGEST-MD5, if you seemingly tried EVERYTHING you've found online without any luck like I did for hours while banging my head into the keyboard, I did finally get facebook chat working with asmack.

                                                                                 

                                                                                If you're getting a failed not authorized for DIGEST-MD5 and are using the asmack library try the following:  go to facebook.com/username, make sure you have a username chosen first, then LOGOUT and log back in using ONLY your username and password.  If you're like me, and hate facebook, but somehow found themselves coding a chat client, you might have had an old account when they used to be based on purely email addresses, so technically before doing the above steps, my userid was xxx@email.com@chat.facebook.com which is retarded on facebooks part.

                                                                                 

                                                                                I'm logged into facebook now from my client using only the asmack lib, no custom mysaslmechanism classes or anything.

                                                                                 

                                                                                Hope that helps some of your frustrated devs out there.