grails-plugins / grails-rest-client-builder

REST client plugin that uses Spring's RestTemplate
http://grails.org/plugin/rest-client-builder
Apache License 2.0
65 stars 32 forks source link

How would you translate given curl call into restbuilder code? #27

Closed sarbogast closed 10 years ago

sarbogast commented 10 years ago

I'm trying to use this plugin to replicate the following curl command:

curl -u CLIENT_ID:CLIENT_SECRET https://api.myfox.me/oauth2/token -d 'grant_type=authorization_code&code=CODE_GENERATED_BY_MYFOX'

But the following code has the server responding that grant_type is missing:

def url = "https://api.myfox.me/oauth2/token"
def resp = rest.post(url, ['grant_type': 'authorization_code', 'code': params.code]) {
      auth clientId, clientSecret
}

Am I doing something wrong or it the error coming from the server I'm connecting to?

graemerocher commented 10 years ago

Yes the map is for URL variables not parameters. The parameters are set in the body:

   def url = "https://api.myfox.me/oauth2/token"
   def resp = rest.post(url) {
         auth clientId, clientSecret
         grant_type = 'authorization_code'
         code = params.code
   }