05-14-2015 08:37
05-14-2015 08:37
I'm currently attempting to build a Node app using the OAuth 2 endpoints and documentation. However, while I am providing "client_id" in the POST body and following along with the documentation, I keep getting a 401 with the error message "Empty client id."
I recreated the POST request in Postman:
POST /oauth2/token HTTP/1.1 Host: api.fitbit.com Content-Type: application/x-www-form-urlencoded Authorization: Basic %EF%BF%BDoP%17%EF%BF%B..... Cache-Control: no-cache client_id=2###F9&grant_type=authentication_code&code=cc483e1fcd6802286d85066787a89dedc85a253c
(Authorization header contains the base-64 encoding of the client ID and secret concatenated with a ":")
As in my Node app, I received the following response:
{
"errors": [{
"errorType": "oauth",
"fieldName": "client_id",
"message": "Empty client id"
}],
"success": false
}Am I doing something wrong, or is this a defect in the FitBit backend?
Answered! Go to the Best Answer.
05-14-2015 11:29
05-14-2015 11:29
Double check your Authorization header, that doesnt look like base64 encoding to me.
For example, if your client_id is ABCDEF and your secret is 8168415c4e2506c7e1adf12c432cd4da
Then your Authorization header should be "Authorization: Basic QUJDREVGOjgxNjg0MTVjNGUyNTA2YzdlMWFkZjEyYzQzMmNkNGRh"
05-14-2015 11:21
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-14-2015 11:21
The error may be incorrect, but I think you're sending the wrong grant_type.
grant_type should be authorization_code, not authentication_code
Best Answer05-14-2015 11:23
05-14-2015 11:23
Whoops, sorry. Got that wrong in Postman. To confirm: changing the value for grant_type still results in the same error.
Best Answer05-14-2015 11:29
05-14-2015 11:29
Double check your Authorization header, that doesnt look like base64 encoding to me.
For example, if your client_id is ABCDEF and your secret is 8168415c4e2506c7e1adf12c432cd4da
Then your Authorization header should be "Authorization: Basic QUJDREVGOjgxNjg0MTVjNGUyNTA2YzdlMWFkZjEyYzQzMmNkNGRh"
05-14-2015 11:52
05-14-2015 11:52
@SunsetRunner, you are right! What I had is some mess that Node's buffer spit out that got URL-encoded. I did the base64 encoding by hand with another tool and it looks much more normal. I am now able to get an access token (well, after also specifying a redirect_uri). Thanks!
Best Answer05-14-2015 11:53
05-14-2015 11:53
No problem! Thank you for bringing up the poor error messaging, we'll get that fixed.
05-17-2015 08:23
05-17-2015 08:23
I also had problems, but finally got it working by adding the redirect_url parameter in the body. The docs say:
Required if specified in the redirect to the authorization page. Must be exact match.
But I never specified that in the redirect because I only have one url. Small deal, things work now but maybe fix the docs or the server 🙂
Best Answer05-18-2015 08:54
05-18-2015 08:54
@johandanforth wrote:
I also had problems, but finally got it working by adding the redirect_url parameter in the body. The docs say:
Required if specified in the redirect to the authorization page. Must be exact match.
But I never specified that in the redirect because I only have one url. Small deal, things work now but maybe fix the docs or the server 🙂
Thank you for reporting this, we will take a look and get this fixed.
Best Answer