powered by Jive Software

Connect to Facebook Chat API using Smack 3.2.2 and X-FACEBOOK-PLATFORM mechanism

Hello.

I try to connect my web application with smack to facebook chat. There is my SlacMechanism implementation (example in scala):

object SASLXFacebookPlatformMechanism {

val NAME = “X-FACEBOOK-PLATFORM”

}

class SASLXFacebookPlatformMechanism(saslAuthentication: SASLAuthentication) extends SASLMechanism(saslAuthentication) with net.liftweb.common.Loggable {

var apiKey: String = _

var access_token: String = _

def getName = SASLXFacebookPlatformMechanism.NAME

override def authenticate() {

getSASLAuthentication.send(new AuthMechanism(getName, “”))

}

override def authenticate(apiKey: String, host: String, access_token: String) {

this.access_token = access_token

this.apiKey = apiKey

this.hostname = host

this.password = access_token

logger.warn(" apikey " + apiKey + " host " + host + " access_token " + access_token)

val mechanisms = Array( getName )

this.sc = Sasl.createSaslClient(mechanisms, null, “xmpp”, host, (new java.util.HashMap[String, String]), this)

authenticate()

}

override def authenticate(apiKey: String, host: String, cbh: CallbackHandler) {

this.apiKey = apiKey

this.hostname = host

logger.warn(" apikey " + apiKey + " host " + host + " access_token " )

val mechanisms = Array( getName )

this.sc = Sasl.createSaslClient(mechanisms, null, “xmpp”, host, (new java.util.HashMap[String, String]), this)

authenticate()

}

override def challengeReceived(challenge: String) {

logger.debug("Chalenge raw: " + challenge)

logger.debug("Chalenge decoded: " + new String(Base64.decode(challenge)))

val parameters = getQueryMap(new String(Base64.decode(challenge), “UTF-8”))

logger.debug("parameters " + parameters)

val responseParams =

(“method” -> parameters(“method”)) ::

(“nonce” -> parameters(“nonce”)) ::

(“access_token” -> access_token) ::

(“api_key” -> apiKey) ::

(“call_id” -> (new GregorianCalendar().getTimeInMillis() / 1000L)) ::

(“v” -> “1.0”) ::

Nil

val responseText = responseParams.map(p => p._1 + “=” + p._2).mkString("&")

logger.debug("responseText: " + responseText)

val response = Base64.encodeBytes(URLEncoder.encode(responseText, “utf-8”).getBytes(“utf-8”), Base64.DONT_BREAK_LINES)

getSASLAuthentication().send(new Response(response))

}

private def getQueryMap(str: String) = {

import collection.JavaConversions._

str.split("\&").map { param =>

val splittedParam = param.split("=")

splittedParam(0) -> (if(splittedParam.length > 1) splittedParam(1) else null)

}.toMap[String,String]

}

}

And using it as such:

val connFig = new ConnectionConfiguration(“chat.facebook.com”, 5222)

connFig.setSASLAuthenticationEnabled(true)

val connection = new XMPPConnection(connFig)

SASLAuthentication.registerSASLMechanism(SASLXFacebookPlatformMechanism.NAME, classOf[SASLXFacebookPlatformMechanism])

SASLAuthentication.supportSASLMechanism(SASLXFacebookPlatformMechanism.NAME, 0)

connection.connect

connection.login(my_app_id, my_access_token_with_xmpp_login)

I check with graph api explorer that i have xmpp_login permission.

But every time i got: SASL authentication X-FACEBOOK-PLATFORM failed: not-authorized:

I check that it uses TLS and failed after i send challenge responce. I complitely stucked, so any help very appriciated. I tried all java examples that i found in this forum, stackoverflow and google.

Hi btd,

Did you found any solution for this yet?