Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[ OAuth2.0 Code Grant Flow ] Getting weird encoded response as token response

ANSWERED

Hello community,

 

I was wondering if someone could help me to address the following:

 

Following this documentation: https://dev.fitbit.com/build/reference/web-api/authorization/oauth2-token/ I was able to initialize the authorization flow and succeeded while requesting the tokens in exchange of the code, however, the issue is that as success response I'm getting this encoded data instead of the JSON object I get from a CURL request:

```
data: '\x1F�\b\x00\x00\x00\x00\x00\x00\x00=�Ms�0\x10\x06��p�N\b Л�ц\x1A\x1C�\n' +
'xaH�H�\x00\x1B�\n' +
'�����^�}wwv\x7F��s���.OPh�\x1A4^�\x16\\��G>[���sG=�0�4�=��\x13�˩׊����j�S\x7FG{�r���H��L��7\x04Ѥ�<���\x1B~&\x16�ڇ�sF���>z�4q�#���D\x14\x1Cx�W�\r��eg�)\x19�ml��D���ݟ�e\x1A�\x119�\x0F���tFڮ��`�2ο��b__vFT�\x1CE>.���:\f�v\x0EM��\r��E�6��q�\n' +
'�Dv�c�Ah�)�:��\x1F�1c�qp\f�N\x19�Ʌ�"l;\b�:�\x1CC�V�L�g��\x14\x18�5l;u-l�\f1�m�xy�nT�k�-�fP�j%kY\x16��\fp�"�mI�<so�*P��*P�\x14=����h�\x7F㥥��\x01\x00\x00'
}
```

I've seen that my Postman/Insomnia requets are failing, but not through the CURL command. The payload from above is comming from axios, so, has anyone resolved this before?

 

Thanks in advance.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Fortunately, I've been able to figure it out and I hope this helps someone out there

 

So... the main issue was that somehow axios@1.2.0 wasn't able to handle the response successfully, even when getting a 200 status code.

 

FIX: downgrade the library at axios@1.1.3.

 

Now, that lead me to a readable debugging session where I realized that I was misconfiguring my HTTP Request because I was assuming that the library would parse an object into a url-encoded string based on the x-www-form-urlencoded header... but it wasn't, so that helped to address the famous missing grant_type issue.

 

Now I'm happily generating user tokens and Fitbit OAuth module is complete.

 

Cheers!

View best answer in original post

Best Answer
2 REPLIES 2

As a reference, this is the successful curl command:

curl -X POST "https://api.fitbit.com/oauth2/token" \
-H "accept: application/json" \
-H "authorization: Basic ****************************" \
-d "client_id=******&grant_type=authorization_code&code=******************&redirect_uri=****************" | jq .

 

 

Best Answer
0 Votes

Fortunately, I've been able to figure it out and I hope this helps someone out there

 

So... the main issue was that somehow axios@1.2.0 wasn't able to handle the response successfully, even when getting a 200 status code.

 

FIX: downgrade the library at axios@1.1.3.

 

Now, that lead me to a readable debugging session where I realized that I was misconfiguring my HTTP Request because I was assuming that the library would parse an object into a url-encoded string based on the x-www-form-urlencoded header... but it wasn't, so that helped to address the famous missing grant_type issue.

 

Now I'm happily generating user tokens and Fitbit OAuth module is complete.

 

Cheers!

Best Answer