playframework/playframework — pull request #1861 by wsargent (2013-10-20 06:30:20+00:00)
Title: Fix for 1779.  Adds query parameters to the URL used for OAuthCalculator signing.

This is only applicable against 2.2.x.

The underlying RequestBuilderBase has a getURL method that constructs a URL plus query string internally, so I exposed it. No tests: had to write an application against twitter to verify this, modified from the Java source code.

```
package controllers

import play.api._
import play.api.mvc._

import play.api.libs.oauth._
import play.api.libs.ws._

import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory

object Application extends Controller {

implicit val context = scala.concurrent.ExecutionContext.Implicits.global

private final val config: Config = ConfigFactory.load
private final val consumerKey: ConsumerKey = new ConsumerKey(config.getString("twitter.consumer_key"), config.getString("twitter.consumer_secret"))
private final val requestToken: RequestToken = new RequestToken(config.getString("twitter.access_token_key"), config.getString("twitter.access_token_secret"))

def index = Action {
Ok(views.html.index())
}

def parameters_in_url = Action.async {
val url: String = "https://api.twitter.com/1.1/users/show.json?screen_name=playframework&include_entities=true"

val calculator = OAuthCalculator(consumerKey, requestToken)
WS.url(url).sign(calculator).get().map {
response => Ok(response.json)
}
}

def parameters_in_ws = Action.async {
val url: String = "https://api.twitter.com/1.1/users/show.json"
val calculator = OAuthCalculator(consumerKey, requestToken)
WS.url(url).withQueryString("screen_name" -> "playframework", "include_entities" -> "true").sign(calculator).get().map {
response => Ok(response.json)
}
}

def parameters_in_both = Action.async {
val url: String = "https://api.twitter.com/1.1/users/show.json?screen_name=playframework&include_entities=true"
val calculator = OAuthCalculator(consumerKey, requestToken)

WS.url(url).withQueryString("screen_name" -> "playframework", "include_entities" -> "true").sign(calculator).get().map {
response => Ok(response.json)
}
}
}
```

Easy way to tell if it's working -- have System.setProperty("debug", "true") and look at Signpost:

WORKING:

[SIGNPOST] Request URL: https://api.twitter.com/1.1/users/show.json?screen_name=playframework&include_entities=true

NOT WORKING:

[SIGNPOST] Request URL: https://api.twitter.com/1.1/users/show.json