Box oauth2: Invalid grant_type parameter or parameter missing

box-api, oauth-2.0

Solution

Looks like Box requires a correct `Content-Type: application/x-www-form-urlencoded` request header in addition to properly URL encoding the parameters. The same seems to apply to refresh and revoke requests.

Also, per RFC 6749, the `redirect_uri` is only

REQUIRED, if the "redirect_uri" parameter was included in the authorization request as described in Section 4.1.1, and their values MUST be identical.

Problem

I don't know what I do wrong, but everytime I tried to obtain the token (after user authentication of course), the result is always Invalid grant_type parameter or parameter missing Possibly related to Box API always returns invalid grant_type parameter on obtaining access token Here is my fiddler result: ``` POST https://api.box.com/oauth2/token HTTP/1.1 Host: api.box.com Content-Length: 157 Expect: 100-continue Connection: Keep-Alive grant_type=authorization_code&code=nnqtYcoik7cjtHQYyn3Af8uk4LG3rYYh&client_id=[myclientId]&client_secret=[mysecret] ``` Result: ``` HTTP/1.1 400 Bad Request Server: nginx Date: Thu, 07 Mar 2013 11:18:36 GMT Content-Type: application/json Connection: keep-alive Set-Cookie: box_visitor_id=5138778bf12a01.27393131; expires=Fri, 07-Mar-2014 11:18:35 GMT; path=/; domain=.box.com Set-Cookie: country_code=US; expires=Mon, 06-May-2013 11:18:36 GMT; path=/ Cache-Control: no-store Content-Length: 99 {"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"} ``` Even following the curl example gives the same error. Any help would be appreciated. Edit: tried with additional redirect_uri params but still the same error ``` POST https://api.box.com/oauth2/token HTTP/1.1 Content-Type: application/json; charset=UTF-8 Host: api.box.com Content-Length: 187 Expect: 100-continue Connection: Keep-Alive grant_type=authorization_code&code=R3JxS7UPm8Gjc0y7YLj9qxifdzBYzLOZ&client_id=*****&client_secret=*****&redirect_uri=http://localhost ``` Result: ``` HTTP/1.1 400 Bad Request Server: nginx Date: Sat, 09 Mar 2013 00:46:38 GMT Content-Type: application/json Connection: keep-alive Set-Cookie: box_visitor_id=513a866ec5cfe0.48604831; expires=Sun, 09-Mar-2014 00:46:38 GMT; path=/; domain=.box.com Set-Cookie: country_code=US; expires=Wed, 08-May-2013 00:46:38 GMT; path=/ Cache-Control: no-store Content-Length: 99 {"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"} ```

Original source