ethanopp / fitly

Self hosted web analytics for endurance athletes
MIT License
185 stars 25 forks source link

Strava OAuth Issues - redirect uri invalid #12

Closed palladionIT closed 3 years ago

palladionIT commented 4 years ago

Hello, I setup fitly with the image from dockerhub and a compose config, did all the necessary steps of filling in the details in the config.ini but when I click the button to connect to strava I get a "bad request - redirect uri invalid"

I run the service on a host in the network on 192.168.8.102 so I replaced all the 127.0.0.1 with that IP. However, when I do that I get an error message from strava as follows.

{"message":"Bad Request","errors":[{"resource":"Application","field":"redirect_uri","code":"invalid"}]} If I use the default 127.0.0.1 strava is not complaining and I can select the OAuth permissions but of course the subsequent redirect goes to the wrong IP.

config.ini redirect_uri = http://192.168.8.102:8050/settings?strava

Strava My API Application 192.168.8.102:8050?strava

Oura is working without any problems. Any ideas on what might be wrong or how to fix it? I can provide more info if necessary. I am just not sure what else might help.

ethanopp commented 4 years ago

Try just 192.168.8.102:8050 in the strava API settings

palladionIT commented 4 years ago

Thanks for the tip. I tried it but it did not work. So I played around a littlebit more and it turns out that Strava only wanted the IP. So after I set it to simply 192.168.8.102 in the Strava API settings it worked for an initial connection but sometimes it looses the authentication in the UI. When I click the "connect Strava" subsequently it immediately connects but seems to sometimes bug out. I will try to find out what exactly is going wrong.

ethanopp commented 4 years ago

What does the debug log show?

Also can you post your docker create statement.

Check the fitness.db apiTokens table to see if a record for strava has been added

palladionIT commented 4 years ago

I used the docker hub image you published and then followed the normal setup of the service. The DB has an access token but from the log files I suspect that the simplified URI without the port lead to some weird OAuth bug because now when I try to start the container authentication with the strava API does not work and I the container stops after too many auth tries with the following exception:

fitly    | Traceback (most recent call last):
fitly    |   File "/usr/local/bin/gunicorn", line 8, in <module>
fitly    |     sys.exit(run())
fitly    |   File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
fitly    |     WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
fitly    |   File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 228, in run
fitly    |     super().run()
fitly    |   File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 72, in run
fitly    |     Arbiter(self).run()
fitly    |   File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 58, in __init__
fitly    |     self.setup(app)
fitly    |   File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 118, in setup
fitly    |     self.app.wsgi()
fitly    |   File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
fitly    |     self.callable = self.load()
fitly    |   File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
fitly    |     return self.load_wsgiapp()
fitly    |   File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
fitly    |     return util.import_app(self.app_uri)
fitly    |   File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
fitly    |     mod = importlib.import_module(module)
fitly    |   File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
fitly    |     return _bootstrap._gcd_import(name[level:], package, level)
fitly    |   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
fitly    |   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
fitly    |   File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
fitly    |   File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
fitly    |   File "<frozen importlib._bootstrap_external>", line 728, in exec_module
fitly    |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
fitly    |   File "/app/src/fitly/app.py", line 32, in <module>
fitly    |     from . import index
fitly    |   File "/app/src/fitly/index.py", line 5, in <module>
fitly    |     from .pages import home, lifting, performance, power, settings
fitly    |   File "/app/src/fitly/pages/settings.py", line 29, in <module>
fitly    |     strava_auth_client = get_strava_client()
fitly    |   File "/app/src/fitly/api/stravaApi.py", line 50, in get_strava_client
fitly    |     refresh_token=client.refresh_token)
fitly    |   File "/usr/local/lib/python3.7/site-packages/stravalib/client.py", line 155, in refresh_access_token
fitly    |     refresh_token=refresh_token)
fitly    |   File "/usr/local/lib/python3.7/site-packages/stravalib/protocol.py", line 158, in refresh_access_token
fitly    |     method='POST')
fitly    |   File "/usr/local/lib/python3.7/site-packages/stravalib/protocol.py", line 215, in _request
fitly    |     raw = requester(url, params=params)
fitly    |   File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 559, in post
fitly    |     return self.request('POST', url, data=data, json=json, **kwargs)
fitly    |   File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 512, in request
fitly    |     resp = self.send(prep, **send_kwargs)
fitly    |   File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 622, in send
fitly    |     r = adapter.send(request, **kwargs)
fitly    |   File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 513, in send
fitly    |     raise ConnectionError(e, request=request)
fitly    | requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.strava.com', port=443): Max retries exceeded with url: /oauth/token?client_id=<HEREISANID>&client_secret=<HEREISASECRET>&refresh_token=<HEREISAREFRESHTOKEN>&grant_type=refresh_token&access_token=<HEREISANACCESSTOKEN> (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7feb53be48d0>: Failed to establish a new connection: [Errno -5] No address associated with hostname'))

I cleared my secret auth data from the ConnectionError string.

ethanopp commented 4 years ago

Try deleting the strava record from the apiTokens table and then click connect strava button again.

It should bring you back to the settings page in fitly, at which point the url should have the code in it, and then once you put your password in to load the settings page, fitly should save the code (token) from the url.

If all of that is working that means the auth worked from the strava since it responded with the token, and if it’s in the apiToken table that means fifty saw the token and saved it.

It also looks like your host is having issues resolving strava No address associated with hostname, if you ssh into the docker, can you curl https://www.strava.com?

ethanopp commented 4 years ago

@palladionIT were you able to get this sorted?

palladionIT commented 4 years ago

@ethanopp sorry for being super slow with providing more info. It is on my todo list but I did not come around to work on it yet. I will reply as soon as I have progress to report.

ethanopp commented 3 years ago

Closing for inactivity - @palladionIT please reopen if still an issue