I'm trying to do an OAuth2 user-credentials post to an OAuth2 service using the Grails RestBuilder plugin.
If I try to specify the post body as a map, I get an error about no message converters for LinkedHashMap.
If I try to specify the body as a String, the post goes through, but none of the variables are posted to the server action.
Here's the post:
RestBuilder rest = new RestBuilder() def resp = rest.post("http://${hostname}/oauth/token") { auth(clientId, clientSecret) accept("application/json") contentType("application/x-www-form-urlencoded") // This results in a message converter error because it doesn't know how // to convert a LinkedHashmap // ["grant_type": "password", "username": username, "password": password] // This sends the request, but username and password are null on the host body = ("grant_type=password&username=${username}&password=${password}" as String) } def json = resp.json I've also tried setting the urlVariables in the post() method call, but the username/password are still null.
This is a very simple post, but I can't seem to get it to work. Any advice would be greatly appreciated.
body(["grant_type": "password", "username": username, "password": password] as JSON). Ideally, if the content-type is JSON, then you can directly send the body in POST asjson {}instead of usingbody.