So I found part of the answer here: https://stackoverflow.com/a/20635782/143733 I had to use the apache default HttpClient as there seemed no way to do it in Play WS class or Sign-Post.
Here is the final async implementation I came up with:
object Twitter extends Controller {
val KEY = ConsumerKey(Play.configuration.getString("twitter.consumer.key").getOrElse("XXXX"),
Play.configuration.getString("twitter.consumer.secret").getOrElse("XXXX"))
val TWITTER_SERVICE_INFO = ServiceInfo(
"https://api.twitter.com/oauth/request_token",
"https://api.twitter.com/oauth/access_token",
"https://api.twitter.com/oauth/authorize", KEY)
val TWITTER = OAuth(TWITTER_SERVICE_INFO,false)
/***
* The following is the reverse oauth step outlined by twitter
*/
def reverse = Action.async {
val client = new DefaultHttpClient();
val params = new java.util.ArrayList[BasicNameValuePair](1)
params.add(new BasicNameValuePair("x_auth_mode", "reverse_auth"))
val consumer = new CommonsHttpOAuthConsumer(KEY.key, KEY.secret)
val post = new HttpPost(TWITTER_SERVICE_INFO.requestTokenURL)
post.addHeader("Content-Type", "application/x-www-form-urlencoded")
post.setEntity(new UrlEncodedFormEntity(params))
consumer.sign(post)
val futureBodyString: Future[String] = future {
val response = client.execute(post)
EntityUtils.toString(response.getEntity())
}
futureBodyString.map {
body => {
Ok(body)
}
}
}
}