05-16-2016 19:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-16-2016 19:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'm passing a grant_type parameter with my POST, but the API is telling me otherwise. Can someone let me know where I'm going wrong?
-- Blocking request (https://api.fitbit.com/oauth2/token) -- Connect d2e3aa20f16f08e813ae93fbf391162a (https://api.fitbit.com:443) -- Client >>> Server (https://api.fitbit.com/oauth2/token) POST /oauth2/token HTTP/1.1\x0d Host: api.fitbit.com\x0d User-Agent: Mojolicious::Plugin::Web::Auth/0.12\x0d Accept-Encoding: gzip\x0d Content-Type: application/x-www-form-urlencoded\x0d Authorization: Basic [REDACTED] \x0d Content-Length: 162\x0d \x0d client_id=[REDACTED]&code=cd9a87e55214353b65c536e2a745ca2ee4ed8b09&grant_type=authorization_code&redirect_uri=http%3A%2F%2F127.0.0.1%3A8088%2Fauth%2Ffitbit%2Fcallback -- Client >>> Server (https://api.fitbit.com/oauth2/token) -- Client <<< Server (https://api.fitbit.com/oauth2/token) HTTP/1.1 400 Bad Request\x0d Date: Tue, 17 May 2016 02:20:09 GMT\x0d Content-Type: application/json;charset=utf-8\x0d Transfer-Encoding: chunked\x0d Connection: keep-alive\x0d Cache-control: no-cache, private\x0d Content-Language: en-CA\x0d Content-Encoding: gzip\x0d Vary: Accept-Encoding\x0d X-Frame-Options: SAMEORIGIN\x0d Server: cloudflare-nginx\x0d CF-RAY: 2a4396b1ca0d2501-ORD\x0d \x0d bb\x0d \x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x00%\x8e1\x0b�P\x0c\x84�J��RZp��"8\x08\x0e�\x83\x88<۴\x0d�^j\x92 *�w_\x15n���\x83{#�\x8a\x1a֧���\x9f#a\x8d\x9c\x1e���E�>\x919\x16\x18�,�s�e3N=,z\x0d�/\x9e\x89\x05\x8cAC$'\x85\x0cNT�\x81\x8d\x1d\x06���j�Qv�W�\x91X��X%a�a\x09\x9d(DQ\x02N���,\x09�| X�\x108�\x15V�\x0d�\x80(��\x9bQ�ɧJ�\x9c\x0b��\x99\x03�]�\x19}��\x87/��\x00\x00\x00\x0d -- Client <<< Server (https://api.fitbit.com/oauth2/token) 0\x0d \x0d [Mon May 16 22:20:17 2016] [error] Authentication error in Fitbit: {"errors":[{"errorType":"invalid_request","message":"Missing 'grant_type' parameter value. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false} at ../Mojolicious-Plugin-Web-Auth/lib/Mojolicious/Plugin/Web/Auth.pm line 28.
Thanks,
Olaf
Answered! Go to the Best Answer.
Accepted Solutions
05-17-2016 20:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-17-2016 20:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
With some help, I got this narrowed down. The way I was Base64 encoding the Authorization header was inserting an additional newline. Once I got rid of that, the error about the missing param was cleared up.

05-17-2016 11:22 - edited 05-17-2016 11:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



05-17-2016 11:22 - edited 05-17-2016 11:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Nothing jumps out as wrong to me in your post. Here's an example of it working:
POST /oauth2/token Accept: */* Authorization: Basic REDACTED Connection: close Content-Length: 132 Content-Type: application/x-www-form-urlencoded Host: api.fitbit.com User-Agent: curl/7.43.0 client_id=XXXXXX&grant_type=authorization_code&redirect_uri=https%3A%2F%2Flocalhost%2F&code=d63e6a5f0b4f6b756b95fd93f696d8b876cd1bf4 Cache-Control: no-cache, private Cf-Ray: 2a49139b7b03286a-SJC Content-Language: en-US Content-Type: application/json;charset=UTF-8 Date: Tue, 17 May 2016 18:19:15 GMT Server: cloudflare-nginx Vary: Accept-Encoding X-Frame-Options: SAMEORIGIN {"access_token":"REDACTED","expires_in":3600,"refresh_token":"9aa8cac389c5ad5f1a57a57c13dada042ff3e06c4aeee8c1b4b7b6f346cb79ef","scope":"location sleep profile activity heartrate social settings nutrition weight","token_type":"Bearer","user_id":"XXXXXX"}

05-17-2016 20:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-17-2016 20:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
With some help, I got this narrowed down. The way I was Base64 encoding the Authorization header was inserting an additional newline. Once I got rid of that, the error about the missing param was cleared up.

