Skip to content

Instantly share code, notes, and snippets.

@uris77
Created January 12, 2013 16:53
Show Gist options
  • Select an option

  • Save uris77/4519213 to your computer and use it in GitHub Desktop.

Select an option

Save uris77/4519213 to your computer and use it in GitHub Desktop.
Obtaining request token from freshbooks with groovy
def index() {
String url = "https://sample.freshbooks.com/oauth/oauth_request.php"
HttpClient httpClient = new DefaultHttpClient()
def params = [
oauth_consumer_key: URLEncoder.encode("mdlabs", "UTF-8"),
oauth_callback: URLEncoder.encode("http://127.0.0.1:8080/FreshbooksOauth/oauth/callback", "UTF-8"),
oauth_version: URLEncoder.encode("1.0", "UTF-8"),
oauth_nonce: URLEncoder.encode("12345678901234567890", "UTF-8"),
oauth_signature_method: 'PLAINTEXT',
oauth_signature: URLEncoder.encode('23ADFDdadffaa123123&', 'UTF-8'),
oauth_timestamp: System.currentTimeMillis()/1000
]
String request_url = url + "?"
def flatParams = params.collect{key, value->
"${key}=${value}"
}.join("&")
request_url += flatParams
HttpPost httpPost = new HttpPost(request_url)
HttpResponse response = httpClient.execute(httpPost)
println "response: ${response.getEntity().getContent()}"
render view: "index", model: [login_href: request_url]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment