FitBit unable to authorize

Hi, hope this can help someone.

If you have multiple Google account registered in chrome/chromium, fitbit authentication in Step 4 will fail if your default account is not the one you used to create developer app. It returns the same errors you get when using wrong URL or with SSL problem.

After I realize that, I used another profile with the google account used in fitbit as default and all worked perfectly. I think incognito mode or another browser less integrated in google ecosystem will solve the same way.

My FitBit Integration was working until yesterday, 20/05/20 and this was prior to the Home Assistant 0.110.0 update but I did update NGINX, not sure if that was the cause but I suddenly lost all my sensors.

I am now trying to re authorise but coming up with

image

also even though I have DuckDNS and NGINX running I still get the callback

image

my local ip.

I have tried putting my config back in my YAML

http:
   base_url: https://redacted.duckdns.org

Still the same.

I re entered my credentials https://dev.fitbit.com/apps and updated my fitbit.conf

Any suggestions to what I am doing wrong or is there a problem with FitBit site?

Same troubles as above. I’ve tried using my standard hassio site through reverse proxy, bypassing proxy by port forwarding 8123 through my domain, tried using nabu casa url, nothing, Fitbit configurator still links me to my internal IP.

base_url is also included, in case anyone asks!

getting one step closer, however, appending /api/fitbit to the end of all three methods does indeed give me the fitbit authorization site, though accepting it immediately ends with error 500, but no sensors to speak of.

I’ve gone as far as clearing cached data just in case that was somehow playing a role, and got zilch.

someone must’ve breathed on the code and broke it again

How? Can you explain the exact steps you’ve followed? I also got it as far as the ‘500’ message. But i’m stuck now. I reached the checkboxes to allow some at:

https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=6_CHAR_CLIENT_ID&redirect_uri=https://EXTERNAL_URL_HASSIO/api/fitbit/callback&scope=SCOPES&state=STATE_HASH

but after pressing ‘allow’, i’ll see the 500 message on Hassio.

Yesterday I updated HA to 111 and HassOS to 4.10.
Wrote NabuCasa both external and internal url.
After these procedures, I was able to create an App and log in2020-06-11 (1) 2020-06-11 (2)

Hi,
Thanks l3v3nu3rt…

Can confirmed working.

  external_url: https://redacted.duckdns.org
  internal_url: https://redacted.duckdns.org

Then got call back at https://redacted.duckdns.org/api/fitbit

I would like to try and replicate it but do not want to break it again…

I have now changed back my internal URL to my http://192

Finally got it to work, but there were 2 issues I encountered.

  • Using Chrome I never got to the page to allow access. I used Firefox instead and that worked.

  • If I didn’t check the check box for all I would get a server error . If all are selected, everything worked. To be fair, it says so on the page.

Hi,
When I tried to authorize, I got the following error message in Chrome:

Developer information: unauthorized_client - Invalid client_id

I just opened the activation link in a different browser and it worked.

1 Like

Same issue here.
Depends from URL.
If i choose my ip:8123 the error is: invalid_request - Invalid redirect_uri parameter value
If i choose duckdns.org:443 the error is: 503

Any help is appreciated.
Regards,

Alessandro

try without 443

This is the entire url:
https://www.fitbit.com/oauth2/authorize?client_id=xxxxxxx&redirect_uri=https%3A%2F%2Fcandeglia.duckdns.org%2Fapi%2Ffitbit%2Fcallback&response_type=code&scope=activity+heartrate+nutrition+profile+settings+sleep+weight&state=Cyg4gLTxhrUee80xXjJhpX7gbCETGw

After this screen:
Cattura

I’ve the same error:
Cattura1

I tried using @AlexKalopsia 's solution. Unfortunately Home Assistant still has the configure pop up window saying “Please authorize Fitbit by visiting http://…/api/fitbit”, so I can’t get past step 0. Is there a fix for this?

1 Like

I fixed this by going to sensor.py and changing the get_url function call to use get_url(hass, allow_internal=False). Took a few minutes, but the default behavior of this call is to return the hass internal URL I am using Home Assistant Cloud. Given the nature of fitbit integration, the devs might want to change the default behavior in sensor.py. my $.02.

Update: I am using Portainer on WDPR2100, Docker HA (not HASS.IO), and the path for sensor.py is /usr/src/homeassistant/homeassistant/components/fitbit/sensor.py.

Do you have the line number where this occurs? I couldn’t find a matching syntax.

UPDATE: I modified the auth url with my duckdns url and was able to get it working.

It also seems like base_url is now deprecated, so the solution above might not work anymore (or might not be needed?)

I think I have found a fix for this now after having to go through authorisation again.

My API is set up to use a https://duckdns:8123 address but the configuration page on HA gives a local IP address and changing this to the duckdns address throws the following error -

Developer information: invalid_request - Invalid redirect_uri parameter value

If you look in the browser address at the top of the fitbit API page you will see the local 192.168 etc address in there so I changed that address to the duckdns address and that worked for me. See the example below -

Before

https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=XXXXXX&redirect_uri=http://192.168.0.60:8123/api/fitbit/callback

to

https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=XXXXXX&redirect_uri=https://duckdnsaddress:8123/api/fitbit/callback

The address above is much longer than I have pasted so you just need to change the local IP address to your https callback address you have configured in the API.

I figured out that I should change the fitbit URL address, but it’s still not working for me. I get a 500 error. Here’s the logs:

2021-01-05 02:30:22 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 118, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_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 126, in handle
    result = handler(request, **request.match_info)
  File "/usr/src/homeassistant/homeassistant/components/fitbit/sensor.py", line 360, in get
    redirect_uri = f"{get_url(hass, require_current_request=True)}{FITBIT_AUTH_CALLBACK_PATH}"
  File "/usr/src/homeassistant/homeassistant/helpers/network.py", line 123, in get_url
    raise NoURLAvailableError
homeassistant.helpers.network.NoURLAvailableError

What error, if any, do you get on the Fitbit API page that I state above ? Is there any new data in the fitbit.conf file apart from your secret and id ?

No error, I’m able to access the URL and allow the app. No new data besides secret and ID. That’s because my error is on line 360 and saving the file happens at a later point.

Have you had this working before ? If not is your setup on the Fitbit API correct and matching your URL ?

Try deleting the fitbit.conf file and restart HA and try again.