home-assistant / home-assistant.io

:blue_book: Home Assistant User documentation
https://www.home-assistant.io
Other
4.71k stars 7.15k forks source link

Error Authorization Fitbit #29748

Open marcellomariano opened 9 months ago

marcellomariano commented 9 months ago

Feedback

I've followed step by step the insructions provided, but when i select "allow permission" on the fitbit authorization page and after i click "link account in the following step, the Home Assistant page respond with an error pop-up. Please give additional instructions to make this integration work. Thanks Marcello

URL

https://www.home-assistant.io/integrations/fitbit/

Version

2023.11.1

Additional information

No response

home-assistant[bot] commented 9 months ago

Hey there @allenporter, mind taking a look at this feedback as it has been labeled with an integration (fitbit) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `fitbit` can trigger bot actions by commenting: - `@home-assistant close` Closes the feedback. - `@home-assistant rename Awesome new title` Renames the feedback. - `@home-assistant reopen` Reopen the feedback. - `@home-assistant unassign fitbit` Removes the current integration label and assignees on the feedback, add the integration domain after the command.
allenporter commented 9 months ago

What's the error? Empty? Anything in the logs?

marcellomariano commented 9 months ago

It appears a blank popup without any info. In the log file I found the following error:

Logger: homeassistant.components.fitbit.config_flow Source: components/fitbit/config_flow.py:68 Integration: fitbit (documentation, issues) First occurred: 18:30:57 (4 occurrences) Last logged: 18:44:41

Failed to create Fitbit credentials: Server error response: 400, message='Bad Request', url=URL('https://api.fitbit.com/oauth2/token')

allenporter commented 9 months ago

@marcellomariano ok thanks. This likely means the oauth client id is not valid https://dev.fitbit.com/build/reference/web-api/troubleshooting-guide/error-messages/#400-bad-request but I don't have additioanl detail / proof here.

(Also not sure why the error message doesn't show up in the UI given we provided strings for this...)

marcellomariano commented 9 months ago

@marcellomariano ok thanks. This likely means the oauth client id is not valid https://dev.fitbit.com/build/reference/web-api/troubleshooting-guide/error-messages/#400-bad-request but I don't have additioanl detail / proof here.

(Also not sure why the error message doesn't show up in the UI given we provided strings for this...)

I also found an additional erro that i think it could be linked to this issue:

Logger: aiohttp.server Source: /usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:403 First occurred: 7 novembre 2023 alle ore 18:26:16 (5 occurrences) Last logged: 10:50:58

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware response = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle result = await handler(request, *request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin return await func(self, request, args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 170, in get return await super().get(request, flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 96, in get result = await self._flow_mgr.async_configure(flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 293, in async_configure result = await self._async_handle_step( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 389, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fitbit/config_flow.py", line 61, in async_step_creation return await super().async_step_creation() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 336, in async_step_creation return await self.async_oauth_create_entry( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fitbit/config_flow.py", line 76, in async_oauth_create_entry profile = await client.async_get_user_profile() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fitbit/api.py", line 72, in async_get_user_profile full_name=profile["fullName"],


KeyError: 'fullName'
allenporter commented 9 months ago

@marcellomariano ok looks like the APi is expecting the full name field, but it is not being returned. would you be also able to turn up debug logging?

logger:
  default: info
  logs:
    homeassistant.components.fitbit: debug
    fitbit: debug

This may return some additional data about the raw response -- however, it may include personal info so it may need to be filtered.

marcellomariano commented 9 months ago

Hi @allenporter , thank you for your support. I set up the dubg logging and i've tried again to launch the fitbit integration. This is the log i can see (it seems be like the previous one, i don't see additional info here):

Logger: aiohttp.server Source: /usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:403 First occurred: 14:56:41 (1 occurrences) Last logged: 14:56:41

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware response = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle result = await handler(request, *request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin return await func(self, request, args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 170, in get return await super().get(request, flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 96, in get result = await self._flow_mgr.async_configure(flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 293, in async_configure result = await self._async_handle_step( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 389, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fitbit/config_flow.py", line 61, in async_step_creation return await super().async_step_creation() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 336, in async_step_creation return await self.async_oauth_create_entry( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fitbit/config_flow.py", line 76, in async_oauth_create_entry profile = await client.async_get_user_profile() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fitbit/api.py", line 72, in async_get_user_profile full_name=profile["fullName"],


KeyError: 'fullName'
allenporter commented 9 months ago

The additional detail will show in the "full log"

marcellomariano commented 9 months ago

Ok, maybe you mean:

2023-11-09 14:56:19.964 INFO (SyncWorker_0) [homeassistant.loader] Loaded fitbit from homeassistant.components.fitbit 2023-11-09 14:56:30.539 WARNING (MainThread) [homeassistant.components.camera] Updating xiaomi_cloud_map_extractor camera took longer than the scheduled update interval 0:00:30 2023-11-09 14:56:41.525 INFO (MainThread) [homeassistant.components.fitbit.config_flow] Successfully authenticated 2023-11-09 14:56:41.813 DEBUG (MainThread) [homeassistant.components.fitbit.api] user_profile_get={'user': {'age': xx, 'ambassador': False, 'avatar': 'https://static0.fitbit.com/images/profile/defaultProfile_100.png', 'avatar150': 'https://static0.fitbit.com/images/profile/defaultProfile_150.png', 'avatar640': 'https://static0.fitbit.com/images/profile/defaultProfile_640.png', 'averageDailySteps': 0, 'challengesBeta': True, 'clockTimeDisplayFormat': '12hour', 'corporate': False, 'corporateAdmin': False, 'dateOfBirth': 'xx-xx-xx', 'displayName': 'xxx', 'displayNameSetting': 'name', 'distanceUnit': 'METRIC', 'encodedId': 'xxx', 'features': {'exerciseGoal': True}, 'foodsLocale': 'it_IT', 'gender': 'MALE', 'glucoseUnit': 'en_US', 'height': 73.62204724409449, 'heightUnit': 'METRIC', 'isBugReportEnabled': False, 'isChild': False, 'isCoach': False, 'languageLocale': 'it_IT', 'legalTermsAcceptRequired': True, 'locale': 'it_IT', 'memberSince': '2014-01-26', 'mfaEnabled': False, 'offsetFromUTCMillis': 3600000, 'sdkDeveloper': False, 'sleepTracking': 'Normal', 'startDayOfWeek': 'SUNDAY', 'strideLengthRunning': 43.46456692913386, 'strideLengthRunningType': 'manual', 'strideLengthWalking': 30.511811023622048, 'strideLengthWalkingType': 'manual', 'swimUnit': 'METRIC', 'temperatureUnit': 'METRIC', 'timezone': 'Europe/Rome', 'topBadges': [], 'visibleUser': True, 'waterUnit': 'en_US', 'waterUnitName': 'fl oz', 'weight': 200.3, 'weightUnit': 'METRIC'}} 2023-11-09 14:56:41.813 ERROR (MainThread) [aiohttp.server] Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware response = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle result = await handler(request, *request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin return await func(self, request, args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 170, in get return await super().get(request, flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 96, in get result = await self._flow_mgr.async_configure(flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 293, in async_configure result = await self._async_handle_step( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 389, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fitbit/config_flow.py", line 61, in async_step_creation return await super().async_step_creation() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 336, in async_step_creation return await self.async_oauth_create_entry( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fitbit/config_flow.py", line 76, in async_oauth_create_entry profile = await client.async_get_user_profile() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fitbit/api.py", line 72, in async_get_user_profile full_name=profile["fullName"],


KeyError: 'fullName'
richardvinger commented 7 months ago

I might be running into the same issue, though now there actually is an error returned by Fitbit:

The app you're trying to connect did not provide valid information to Fitbit. Please report this issue to them.

Developer information: invalid_request - Invalid redirect_uri parameter value

The redirect_urI that I can see is https%3A%2F%2Fmy.home-assistant.io%2Fredirect%2Foauth

allenporter commented 7 months ago

@richardvinger no, not the same issue -- the error messages are different. See the integration instructions https://www.home-assistant.io/integrations/fitbit/ under Generate Client ID and Secret step 6

richardvinger commented 7 months ago

Thanks for keeping me honest. Is it as intended that when setting up the integration from the UI, this prerequisite isn't mentioned?

allenporter commented 7 months ago

I agree that UI flows should indicate what they need setup, so open to feedback on what is missing.

I just tried this out from a fresh install and this is the screen I see:

Fitbit Application Credentails

This links to the instructions "view fitbit documentation" I linked to which mention this. My impression is that in order to use this from the UI you need to register a fitbit application, and the link calling this out are right next to the instructions that tell you how to do that registration.

Let me know if you are seeing something different.

richardvinger commented 7 months ago

I wasn't getting the screen you screenshotted. Instead, when trying to add the integration, I'm immediately sent to the browser for OAuth.

The culprit seems to be that I have invalid (apparently) developer credentials in Home Assistant from a previous installation of the Fitbit integration. Under Devices & Services -> App Credentials, I see an entry for Fitbit. Deleting it restores the flow as you described.

I wonder if it would be better if the screen you screenshotted is always displayed, even if there already are credentials in Home Assistant. Given that the user appears to be reinstalling the integration, there's a fair chance that the credentials need an update anyway.

As for why my developer credentials are invalid I'm not sure, though I'm thinking that the migration of my Fitbit account to a Google account could be the reason.

Op wo 10 jan 2024 19:20 schreef Allen Porter @.***>:

I agree that UI flows should indicate what they need setup, so open to feedback on what is missing.

I just tried this out from a fresh install and this is the screen I see: Fitbit.Application.Credentails.png (view on web) https://github.com/home-assistant/home-assistant.io/assets/6026418/875da5f0-98df-4561-8e4e-143ddf676ad4

This links to the instructions I linked to which mention this. My impression is that in order to use this from the UI you need to register a fitbit application, and the link calling this out are right next to the instructions that tell you how to do that registration.

Let me know if you are seeing something different.

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/home-assistant.io/issues/29748#issuecomment-1885385549, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5WEEU62MCC3GXK2I7YTHK3YN3LVZAVCNFSM6AAAAAA7BSCH7SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBVGM4DKNJUHE . You are receiving this because you were mentioned.Message ID: @.***>

allenporter commented 7 months ago

Perhaps the credentials were there imported from .yaml and created using the old process which was also before the new redirect URL was required.

I agree that generally application credentials do have a complex UI balancing ease of use of the common case (if you have credentials, use them) vs being very verbose and explicit when things go wrong (e.g. the flow can't really tell you got stuck). I'll keep thinking about this. (It's also not specific to fitbit, and the same for all oauth integrations)