marcsello / ezotv

Website hosted at ezotv.marcsello.com
https://ezotv.marcsello.com
Creative Commons Zero v1.0 Universal
0 stars 0 forks source link

oauthlib causes internal server error #5

Closed marcsello closed 4 years ago

marcsello commented 4 years ago

oauthlib causes internal server error when the access token expires.

webapp_1  | [2020-01-29 10:40:54,932] ERROR in app: Exception on /dashboard [GET]
webapp_1  | Traceback (most recent call last):
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app
webapp_1  |     response = self.full_dispatch_request()
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1951, in full_dispatch_request
webapp_1  |     rv = self.handle_user_exception(e)
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1820, in handle_user_exception
webapp_1  |     reraise(exc_type, exc_value, tb)
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
webapp_1  |     raise value
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1949, in full_dispatch_request
webapp_1  |     rv = self.dispatch_request()
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1935, in dispatch_request
webapp_1  |     return self.view_functions[rule.endpoint](**req.view_args)
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/flask_classful.py", line 268, in proxy
webapp_1  |     response = view(**request.view_args)
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/flask_classful.py", line 239, in inner
webapp_1  |     return fn(*args, kwargs)
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/flask_login/utils.py", line 261, in decorated_view
webapp_1  |     return func(*args, kwargs)
webapp_1  |   File "/ezotv/views/dashboard_view.py", line 41, in index
webapp_1  |     r = discord.get("/api/users/@me")
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 546, in get
webapp_1  |     return self.request('GET', url, **kwargs)
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/flask_dance/consumer/requests.py", line 194, in request
webapp_1  |     return super(OAuth2Session, self).request(
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/requests_oauthlib/oauth2_session.py", line 477, in request
webapp_1  |     url, headers, data = self._client.add_token(
webapp_1  |   File "/usr/local/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 198, in add_token
webapp_1  |     raise TokenExpiredError()
webapp_1  | oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired)
marcsello commented 4 years ago

It was both a wrong implementation of token saving (see 5f270eba4539c432572196180d10cad8ed122a4e and 5c395eab1cb66cfe68701d6166e4bda4157ede6f)

And FlaskDance not renewing the access token automatically. The later is fixed by forcing users to log out when their token expired (see 286fcca8a025462cbf4acb06162c268cc1575ebc)