How to perform X-FACEBOOK-PLATFORM and Google Talk X-OAUTH2 XMPP authentication with PHP Jaxl library

Standard

Ever since Jaxl library first introduced support for X-FACEBOOK-PLATFORM XMPP authentication mechanism, it has changed significantly. Also, Google Talk now supports OAuth 2.0 Authorization, an XMPP extension to allow users to log in using OAuth 2.0 credentials.

Both these mechanisms are a big win for XMPP developers, since real-time conversation experience can now be provided to their application users without asking them for their passwords. In this blog post, I will demonstrate how to perform X-FACEBOOK-PLATFORM and X-OAUTH2 XMPP authentication mechanism using Jaxl v3.x PHP Library.

X-FACEBOOK-PLATFORM XMPP Authentication
Here is a quick guide on how to perform X-FACEBOOK-PLATFORM XMPP authentication using xfacebook_platform_client.php which comes bundled with Jaxl v3.x examples:

  • Visit Facebook Developer Apps page and register your application
  • Once registered, visit access token tool to get required parameters to perform X-FACEBOOK-PLATFORM authentication Facebook Access Token Tool
  • Click on the debug button next to User Token and make sure xmpp_login is one of the extended permissions (scope)
  • Enter downloaded Jaxl library folder and run from command line as follows:

    $ php examples/xfacebook_platform_client.php fb_user_id_or_username fb_app_key fb_access_token

You can now take the source code of xfacebook_platform_client.php and customize it for your application needs.

Google Talk X-OAUTH2 XMPP Authentication
Here is a quick guide on how to perform Google Talk X-OAUTH2 XMPP authentication using xoauth2_gtalk_client.php which comes bundled with Jaxl v3.x examples:

  • Visit Google OAuth Playground and input https://www.googleapis.com/auth/googletalk as the required scope. Press “Authorize API” and then “Allow Access” button on the redirected page
  • In step 2, simply press “Exchange authorize code for tokens” and copy the access token
  • Enter downloaded Jaxl library folder and run from command line as follows:

    $ php examples/xoauth2_gtalk_client.php username@gmail.com access_token

You can now take the source code of xoauth2_gtalk_client.php and customize it for your application needs.

Wasn’t that simple :)

  • Muralli

    I liked it Thank You for the update

  • ducna

    Can I perform x-messenger-oauth2 to authenticate with windows live messenger with php jaxl library?

    • http://abhinavsingh.com Abhinav Singh

      Hi, I have replied to your query on stackoverflow here.

  • http://gunify.com Oscar

    Hi Abhinav,

    I got the gtalk client to work in the command line (BTW it wasn’t working because the sample client script didn’t have the host and port for gtalk). Anyway, I don’t really need a client for chatting, all I want to do is set the presence to dnd and exit. Then later run it again and set the presence back to what it was and exit.

    How do you suggest I accomplish this?

  • ios developers

    We (super feeder) have a similar web app where XMPP is part of the application. The choice we made is to not replicate the user data across both the web app storage and the XMPP server. You can build your own authentication mechanism using the web app’s data store with e-jabbered, it’s pretty easy. This way, you only have 1 single place where user data is …

  • http://lophliphluph.com.nu lophliphluph

    what wrong whit this?
    Parse error: syntax error, unexpected T_FUNCTION in /home/www/lophliphluph.cu.cc/JAXL-3.x/examples/xfacebook_platform_client.php on line 69

  • Gökhan Barış Aker

    Hi, i succeed to execute facebook echo bot and it is working perfectly. However, i am unable to send server originated message to users in friend list. İ asked the SO question with more details at http://stackoverflow.com/questions/14338632/how-to-send-facebook-chat-message-via-jaxl

  • Bavaglino

    Hi there.

    I tried to get it work, but i can’t make it.

    I want to perform inside of a PHP workflow to send a chat message to Facebook. I already have a Token, i have xmpp_login rights, but there is no way to get a message to facebook.

    Is there any small code snippet which can help me understand how i can make it?

    Thanks in advance
    Bavaglino

    • http://abhinavsingh.com Abhinav Singh

      This is an echo bot for facebook chat using xmpp_login workflow. Run it, send a message to the user with whose oauth token this bot is running, it will echo back the message to you. Take it forward from this script.

  • ravisoni6262

    Hii..

    Great work, I was trying registering an app for x-facebook-authentication but i am confused with app scope please suggest what sholud be taken from below points :

    1) Website with Facebook Login

    2)App on Facebook

    3)Mobile Web

    4)Native iOS App

    5)Native Android App

    6)Page Tab

    Please reply