8000 Can't authorise Withings · Issue #26716 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Can't authorise Withings #26716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
quantummobile opened this issue Sep 19, 2019 · 64 comments · Fixed by #27310 or #27404
Closed

Can't authorise Withings #26716

quantummobile opened this issue Sep 19, 2019 · 64 comments · Fixed by #27310 or #27404

Comments

@quantummobile
Copy link

Home Assistant release with the issue:

0.99.0

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.):

Hass.io
Component/platform:

https://www.home-assistant.io/components/withings/

Description of problem:

Can't authorise the app, get error:

500 Internal Server Error
Server got itself in trouble

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

Traceback (if applicable):


Additional information:

@jlauwers
Copy link

Same here for docker.

@wills106
Copy link
wills106 commented Sep 19, 2019

As per ticket #26613 I can't Authorise Withings. I couldn't get this to work on 0.99b1 - 0.99b3

In my configuration.yaml I have the following:

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

withings:
  client_id: !secret withings_id
  client_secret: !secret withings_secret
  profiles: 
    -  William

logger:
  default: info
  logs:
    homeassistant.components.withings: critical

When I go to the integrations page and select Withings and then choose my profile/user I am redirected to the authorization API website.
I select "Allow this app"
After that I can see a very short glimpse of a message coming up on the integration screen and then it goes back to the "Allow this app" Page.
If I press the "Allow this app" button for a second time I get

500 Internal Server Error
Server got itself in trouble

I am running HASSIO as a native package on a Synology NAS, also using the built in reverse proxy.

This is the log I get:

2019-09-19 07:33:54 ERROR (MainThread) [frontend.js.latest.201909181] http://192.168.1.210:8123/frontend_latest/chunk.43dcfc6e5b8d18714299.js:1007:164 Uncaught TypeError: Cannot read property 'item' of undefined
2019-09-19 07:34:08 ERROR (MainThread) [aiohttp.server] Error handling request
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 40, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 73, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 231, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 128, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 155, in get
    return await super().get(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 78, in get
    result = await self._flow_mgr.async_configure(flow_id)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 89, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 132, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/withings/config_flow.py", line 132, in async_step_finish
    return await self._async_create_session(profile, code)
  File "/usr/src/homeassistant/homeassistant/components/withings/config_flow.py", line 139, in _async_create_session
    credentials = auth_client.get_credentials(code)
  File "/usr/local/lib/python3.7/site-packages/nokia/__init__.py", line 86, in get_credentials
    client_secret=self.consumer_secret)
  File "/usr/local/lib/python3.7/site-packages/requests_oauthlib/oauth2_session.py", line 307, 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 421, 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 431, in parse_token_response
    validate_token_parameters(params)
  File "/usr/local/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 441, in validate_token_parameters
    raise MissingTokenError(description="Missing access token parameter.")
oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter.
2019-09-19 07:34:12 ERROR (MainThread) [aiohttp.server] Error handling request
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 40, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 73, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 231, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 128, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/withings/config_flow.py", line 182, in get
    flow_id, {const.PROFILE: profile, const.CODE: code}
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 89, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 132, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/withings/config_flow.py", line 132, in async_step_finish
    return await self._async_create_session(profile, code)
  File "/usr/src/homeassistant/homeassistant/components/withings/config_flow.py", line 139, in _async_create_session
    credentials = auth_client.get_credentials(code)
  File "/usr/local/lib/python3.7/site-packages/nokia/__init__.py", line 86, in get_credentials
    client_secret=self.consumer_secret)
  File "/usr/local/lib/python3.7/site-packages/requests_oauthlib/oauth2_session.py", line 307, 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 421, 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 431, in parse_token_response
    validate_token_parameters(params)
  File "/usr/local/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 441, in validate_token_parameters
    raise MissingTokenError(description="Missing access token parameter.")
oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter.

@probot-home-assistant
Copy link

Hey there @vangorra, mind taking a look at this issue as its been labeled with a integration (withings) you are listed as a codeowner for? Thanks!

@markc123-git
Copy link
markc123-git commented Sep 19, 2019

I have the same issue - first it failed with invalid call back ID - fixed by adding the nabu casa base URL to config and the Withings API, then a failure to redirect from the auth screen to HA - fixed by not having a space in the profile

Now I am hitting the same wall - first attempt to link bounces you back to the integrations screen, second the 500 server error.

Thu Sep 19 2019 10:04:57 GMT+0100 (British Summer Time)
Error handling request
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 40, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 73, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 231, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 128, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 155, in get
    return await super().get(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 78, in get
    result = await self._flow_mgr.async_configure(flow_id)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 89, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 132, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/withings/config_flow.py", line 132, in async_step_finish
    return await self._async_create_session(profile, code)
  File "/usr/src/homeassistant/homeassistant/components/withings/config_flow.py", line 139, in _async_create_session
    credentials = auth_client.get_credentials(code)
  File "/usr/local/lib/python3.7/site-packages/nokia/__init__.py", line 86, in get_credentials
    client_secret=self.consumer_secret)
  File "/usr/local/lib/python3.7/site-packages/requests_oauthlib/oauth2_session.py", line 307, 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 421, 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 431, in parse_token_response
    validate_token_parameters(params)
  File "/usr/local/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 441, in validate_token_parameters
    raise MissingTokenError(description="Missing access token parameter.")
oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter.`

@Bluhme1
Copy link
Bluhme1 commented Sep 19, 2019

Same here. Continue running the Withings component as a custom component and everythings works. The problems appear when switching to the merged component in 0.99.

@cben0ist
Copy link

Same issue for me with the following error log:
oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter.

@Thomasdmm
Copy link

I have this message error for me

{"errors":[{"message":"redirect_uri_mismatch: The redirect URI provided is missing or does not match partner callback url"}]}

@wills106
Copy link

@Thomasdmm

Are you accessing HA locally? Ie 192.168.xxx.xxx
Try adding

http:
  base_url: https://external.domain.org

Then access it through your external address.
I think you need some form of externall access to HA. But that may get addressed with the broken flow.

@Thomasdmm
Copy link

Yes I acces to HA locally or with my nabu account
I try to put the nabu account for call back url but this doesn't work and my localy adress 10.0.x.x:8123 is not accept.
I put

http:
  base_url: https://external.domain.org

In the configuration.yaml ? at the beginning ?

Thnaks for help

@Thomasdmm
Copy link

Hello again I put

http:
  base_url: https://external.domain.org

at the beginning of my Configuration Yaml
I put https://external.domain.org in my callback url on the site of withings and i receive this message error

{"Error":{"Code":200,"Msg":"Invalid method"},"Method":"withings"}

@wills106
Copy link

I think we just need to sit and wait for now.
I'm not sure if #26720 will fix the issue or if we need the Nokia python library updating?
Perhaps @markc123-git can point you in the direction with the Nabu setup as it looks like that's what he is using for external access, from a couple of posts above.

@Thomasdmm
Copy link

When i put my nabu adress on base_url and in withings callback url
I receive this message

500 Internal Server Error
Server got itself in trouble

@wills106
Copy link
wills106 commented Sep 19, 2019

Yea, that's correct.
That's where we are getting stuck, see my first post (third one on here)

@derfloh
Copy link
derfloh commented Sep 20, 2019

I had the same problem ( Server got itself in trouble/Missing token). I'm running HA on a raspberry in docker ( homeassistant/home-assistant:0.99.0 ).

To be able to successfully finish the config flow, I had to change a line in the nokia lib ( https://github.com/orcasgit/python-nokia/blob/1.2.0/nokia/__init__.py#L86 ).
In my docker container it's in /usr/local/lib/python3.7/site-packages/nokia/__init__.py

I've added
, include_client_id=True

to the fetch_token() call.

@quantummobile
Copy link
Author

Hi @vangorra, any chance to have this fixed soon?

@sjabby
Copy link
Contributor
sjabby commented Sep 20, 2019

My understanding of this issue is due to a change in withings API and a request as been made for the lib: orcasgit/python-nokia#38

@coalfield
Copy link

Same issue here, it loops then 500 error

@danieledwardgeorgehitchcock

I had the same problem ( Server got itself in trouble/Missing token). I'm running HA on a raspberry in docker ( homeassistant/home-assistant:0.99.0 ).

To be able to successfully finish the config flow, I had to change a line in the nokia lib ( https://github.com/orcasgit/python-nokia/blob/1.2.0/nokia/__init__.py#L86 ).
In my docker container it's in /usr/local/lib/python3.7/site-packages/nokia/init.py

I've added
, include_client_id=True

to the fetch_token() call.

Can confirm this fix worked for me!

@Bluhme1
Copy link
Bluhme1 commented Sep 20, 2019

I'm afraid it is a bit too complicated for me.
But when you have identified the problem and on top of that found a solution, we can hope that there will be a fix very soon.
Could you perhaps post the revised file, so that it is just a question of copying it to the right place?

@danieledwardgeorgehitchcock
Copy link
danieledwardgeorgehitchcock commented Sep 20, 2019

As mentioned and referenced above, this is an issue with the python-nokia library, not Home Assistant. It will need to be resolved there in order that the changes propagate through to HA.

@quantummobile
Copy link
Author

As mentioned and referenced above, this is an issue with the python-nokia library, not Home Assistant. It will need to be resolved there in order that the changes propagate through to HA.

Yeah, and what exactly needs to be done and by whom to resolve this issue? What's expected resolution time?

@sjabby
Copy link
Contributor
sjabby commented Sep 20, 2019

@quantummobile check the link i posted above.

@quantummobile
Copy link
Author

@quantummobile check the link i posted above.

I'm sorry, but that doesn't make things any clearer to me :)

@Naesstrom
Copy link

In my docker container it's in /usr/local/lib/python3.7/site-packages/nokia/init.py
I've added
, include_client_id=True
to the fetch_token() call.

Can I find this location somewhere in a hass.io install to and change it manually or do I need to wait for a patch

@sjabby
Copy link
Contributor
sjabby commented Sep 20, 2019 via email

@sjabby
Copy link
Contributor
sjabby commented Sep 20, 2019 via email

@Naesstrom
A3E2 Copy link

I changed it in my hassio setup today and had the same path as described.

Hmm, I'm missing the nokia folder no such file or directory: /usr/local/lib/python3.7/site-packages/nokia/
Also checked the site-packages with ls, hassio on rpi3

@markc123-git
Copy link

Hmm, I'm missing the nokia folder no such file or directory: /usr/local/lib/python3.7/site-packages/nokia/
Also checked the site-packages with ls, hassio on rpi3

Same here, hassio on a VM, no nokia folder

@wills106
Copy link

We are waiting on the Nokia python library being updated, which is out off the hands of the HomeAssistant people.

@parberge
Copy link
Contributor
parberge commented Sep 23, 2019

@wills106 Is there an ongoing PR and/or issue to link to? So we home assistant users can go and try to influence the importance of this update 😄

@Bluhme1
Copy link
Bluhme1 commented Sep 23, 2019

Try to look at
orcasgit/python-nokia#38
And ask for a solution

@matty0511
Copy link

i did the workaround and im still getting the same 500 internal server error

@vangorra
Copy link
Contributor
vangorra commented Oct 5, 2019

the maintainer confirmed the Project is dead. I'll fork and fix this weekend

@vangorra
Copy link
Contributor
vangorra commented Oct 8, 2019

Fix is ready to be merged.
BTW: Here's the new maintained withings api project. https://github.com/vangorra/python_withings_api

@vangorra
Copy link
Contributor

This fix won't make it into 0.100 of HA. The maintainers reverted the fix (#27385) after the release scripts failed. This was caused by the withings-api module not using a static version number in setup.py.
This has been fixed an a new PR has been submitted. #27404

@Naesstrom
Copy link

If we did any of the workarounds here do we need to change something back once it's in the release?

@cambiph
Copy link
cambiph commented Oct 11, 2019

I am really sorry but I don't get what I have to do to get my Withings devices to work with HA.
As described above, I edited my configuration.yml and added my nabu.casa URL as base_url but when I approve via Withings, I just get a timeout on:
http://***.ui.nabu.casa/api/withings/authorize?flow_id=***&profile=***&code=***&state=***

Is the workaround as mentioned by @Skeletorjus still needed after the fix of @vangorra?
Really confused, sorry.

@carlostico
Copy link

If we did any of the workarounds here do we need to change something back once it's in the release?

Anyone ?

@vangorra
Copy link
Contributor

You should have to change nothing as the new ha code will overwrite any changes. If you're using a custom component, then you'll probably have to remove it.

@carlostico
Copy link

You should have to change nothing as the new ha code will overwrite any changes. If you're using a custom component, then you'll probably have to remove it.

Just used the "Custom deps deployment" and fixed the auth problem...

@northpower25
Copy link

With HA Version 0.100.1 and 0.100.2 after i click on "allow this app" i got the error "call to the webservice failed" . Has anyone else the same problem by activate the witings connection to Home Assistant? (API URI URL and HA URL are reachable from the web)

@philipp-schottkowsky
Copy link

With HA Version 0.100.1 and 0.100.2 after i click on "allow this app" i got the error "call to the webservice failed" . Has anyone else the same problem by activate the witings connection to Home Assistant? (API URI URL and HA URL are reachable from the web)

Yes, I also get the message "call to the webservice failed" with HA Version 0.100.2. With version before 0.100 I got the message "500 Internal Server Error".

@northpower25
Copy link

@philipp-schottowsky
Follow the following bug i‘ve report to that issue
#27619

@velijv
Copy link
velijv commented Oct 17, 2019

The workaround works. However I ran into this issue:

  • in Withings OAuth page, you can't add a port (https://xxx.duckdns.org:8123)
    This is not a valid URL.
    It redirects back to my DuckDNS url, and I can add the port number manually in the address bar, and it syncs. However this wont work for its automatic polling...

@northpower25
Copy link

With HA Version 0.100.1 and 0.100.2 after i click on "allow this app" i got the error "call to the webservice failed" . Has anyone else the same problem by activate the witings connection to Home Assistant? (API URI URL and HA URL are reachable from the web)

Yes, I also get the message "call to the webservice failed" with HA Version 0.100.2. With version before 0.100 I got the message "500 Internal Server Error".

after i wrote to Withings SDK Support now if works it should be for me an withings problem and not an integration problem.

@roitto
Copy link
roitto commented Oct 18, 2019

I have same issue as the @velijv

I switched to port 430 and i was able to connect to the api. I would rather still use different port than 430.

But i think that the home assistant is not currently polling data from the api. I get lot of these "No measure groups found, setting state to None" or "Sleep data has no series, setting state to None" to my logs.

@momab
Copy link
momab commented May 4, 2020

Is there any news regarding this Problem?
Do I HAVE to make Home Assistant publicly available for the Withings Integration to work?

@vangorra
Copy link
Contributor
vangorra commented May 4, 2020

This is the only supported method of connecting. Withings requires the URL you provide must be https running in port 443 and is accessible. Their servers check when you set the callback URL for the developer account.

For development purposes, your can work around this very easily if you understand how oauth2 works. This method is unsupported, hence it does not exist in the documentation as it gets complicated. When setting up you withings dev account, the callback URL can be anything that withings can check is online when you setup your developer account, like https://myblackhole.somedomain.com/auth/external/callback. So long as that has a valid certificate and responds at all, the withings server is satisfied. You can even shut off the http server after setting up the dev account. Withings doesn't recheck, as far as I can tell.
On the HA side, your base URL needs to be https://myblackhole.somedomain.com. When you setup then integration, the withings server will require you to authorize this app and redirect you to https://myblackhole.somedomain.com/auth/external/callback with a lot of data on the path. Just replace https://myblackhole.somedomain.com in the URL with the internal address of the HA instance that started the setup. Something like http://10.10.0 22:8123

@chriswood1001
Copy link

Hi @vangorra — Now that home assistant has migrated from base_url to external/internal_url, is there another workaround? I've successfully paired in the past, (always with difficulty and several attempts), but now I'm completely blocked. This is what I've tried:

  1. Remove base_url from the http section of configuration.yaml (restart)
  2. Navigate to home assistant, /config/core and set external_url to "https://xxxx.duckdns.org" and internal_url to "http://192.168.7.xxx:8123" (restart)
  3. Navigate to /config/integrations, select Withings, new tab opens.
  4. The URL (https://account.withings.com/oauth2_user/....) has "redirect_uri=http%3A%2F%2F192.168.7.xxx%3A8123%2Fauth%2Fexternal%2Fcallback", so I change that to "redirect_uri=https%3A%2F%2Fxxxx.duckdns.org%2Fauth%2Fexternal%2Fcallback" and hit enter (navigate there).
  5. I select my user, select "Allow this app"
  6. Withings refreshes back to step 4. I change the URL (again), select my user (again), Allow this app (again)
  7. I'm directed to: "https://xxxx.duckdns.org/auth/external/callback?code=abc&state=xyz" with the message: "500 Internal Server Error. Server got itself in trouble"

I've tried making the request when signed into home assistant using my internal (192.168.7.xxx:8123) URL, and when signed in to external (https://xxxx.duckdns.org), and from outside my network (mobile data). I've also double checked that my Withings developer account has the callback URL: "https://xxxx.duckdns.org/auth/external/callback"

Thoughts?
I appreciate all the help.

@wills106
Copy link

@chriswood1001 Try setting your "internal url" to your duckdns one.
That's how I got it to work on my setup

@chriswood1001
Copy link

@wills106 — perfect! that worked.
It's not intuitive to set the internal_url for an external service, but what matters is that it worked.

@matteos1
Copy link
matteos1 commented Jun 6, 2020

@wills106 work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

0