FitBit Auth Error still

I am getting a 500 server error in the very last step of the FitBit authentication after checking all the boxes at the FitBit website I am redirected to. After following through several threads, this seems to be a common problem that rears its head periodically. Running Home Assistant Core 0.108.5 on a Pi

I followed the steps given to create a custom component and loaded the files from the https://github.com/home-assistant/core/tree/master/homeassistant/components/fitbit directory and changed the manifest.json as suggested:

{
  "domain": "fitbit",
  "name": "Fitbit",
  "documentation": "https://www.home-assistant.io/integrations/fitbit",
  "requirements": ["fitbit==0.3.1"],
  "dependencies": ["configurator", "http"],
  "codeowners": ["@robbiet480"]
}

And this is the error, same one everyone seems to get at some point:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 120, in handle
    result = handler(request, **request.match_info)
  File "/config/custom_components/fitbit/sensor.py", line 358, in get
    result = self.oauth.fetch_access_token(data.get("code"), redirect_uri)
  File "/usr/local/lib/python3.7/site-packages/fitbit/api.py", line 147, in fetch_access_token
    code=code)
  File "/usr/local/lib/python3.7/site-packages/requests_oauthlib/oauth2_session.py", line 244, in fetch_token
    self._client.parse_request_body_response(r.text, scope=self.scope)
  File "/usr/local/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 411, in parse_request_body_response
    self.token = parse_token_response(body, scope=scope)
  File "/usr/local/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 379, in parse_token_response
    validate_token_parameters(params)
  File "/usr/local/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 386, in validate_token_parameters
    raise_from_error(params.get('error'), params)
  File "/usr/local/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/errors.py", line 415, in raise_from_error
    raise cls(**kwargs)
oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client)

configuration.yaml (mydomain replaced with my actual domain):

http:
   base_url: https://mydomain.duckdns.org
   server_port: 8123
   ssl_certificate: /ssl/fullchain.pem
   ssl_key: /ssl/privkey.pem

...
# Fitbit
sensor:
  - platform: fitbit
    clock_format: 12H
    monitored_resources:
      - "activities/steps"

@chkaloon I’m getting the same error. Did you find a way to resolve the issue?

No, I gave up for the time being. I’m hoping a future release fixes things.

I figured out a workaround! The issue is related to the Fitbit integration using OAUTH that requires https and not http. What I did was:

  • Temporarily changed my internal URL to the same https duckdns URL I use for my external URL.
  • Then, deleted my existing fitbit.conf and rebooted Home Assistant.
  • This time, when it prompted me to configure Fitbit, I saw my external URL in the instructions for setting up the Fitbit developer app. (This is key to the callback working properly)
  • Updated the credentials in the fitbit.conf with Client ID and secret.
  • Then, finally the last step to authenticate with Fitbit worked! (If you see a screen that says the client ID is incorrect, you may need to update the URL that’s trying to call to Fitbit to make sure it has the correct client ID (mine seemed to be cached to an older Fitbit app integration as I started from scratch)

You can then change your internal URL back to the HTTP HA IP (:8123). Hope this workaround helps!

Perhaps I spoke too soon. This process enables me to re-authenticate with Fitbit, but still throws the same error in the logs. And the entities don’t appear to be created. :confused:

oauthlib.oauth2.rfc6749.errors.InvalidGrantError: (invalid_grant)

Bummer. I wonder if it’s a FitBit issue or a HA integration issue.

Issue for this