burnnat / ha-polar

Polar fitness tracking integration for Home Assistant.
MIT License
9 stars 8 forks source link

oAuth Issue - invalid_grant #4

Open ahilles107 opened 4 years ago

ahilles107 commented 4 years ago

I can't make it work with Home Assistant 0.104.3.

On second step (callback from polar to home assiatant) i have this error in logs (in browser i can see 500 error).


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 135, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 123, in handle
    result = await result
  File "/config/custom_components/polar/config_flow.py", line 137, in get
    await hass.config_entries.flow.async_configure(flow_id, {'code': code})
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 130, 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 172, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/config/custom_components/polar/config_flow.py", line 97, in async_step_oauth
    token_response = self.accesslink.get_access_token(user_input['code'])
  File "/usr/local/lib/python3.7/site-packages/accesslink/accesslink.py", line 40, in get_access_token
    return self.oauth.get_access_token(authorization_code)
  File "/usr/local/lib/python3.7/site-packages/accesslink/oauth2.py", line 75, in get_access_token
    headers=headers)
  File "/usr/local/lib/python3.7/site-packages/accesslink/oauth2.py", line 143, in post
    return self.__request("post", endpoint=endpoint, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/accesslink/oauth2.py", line 137, in __request
    return self.__parse_response(response)
  File "/usr/local/lib/python3.7/site-packages/accesslink/oauth2.py", line 121, in __parse_response
    raise HTTPError(message, response=response)
requests.exceptions.HTTPError: 400 Bad Request: {"error":"invalid_grant"}```
jurgenhaas commented 4 years ago

Exact same issue here. With HA v0.108.1

jurgenhaas commented 4 years ago

@ahilles107 are you running behind a reverse proxy? Mine is behind HaProxy and what help me out are the instructions here: https://www.home-assistant.io/docs/ecosystem/haproxy/

In particular the http settings in configuration.yaml have been essential