Token refresh in Python API definitive solution

Hello,

i created a new topic to find a definitve solution for all python API users of Asana. The automatic token refresh is one of the big issues with the current Python API and remains unsolved so far. Many developers need their application to run 24/7 on a server but to achieve this a reliable oauth token refresh is necessary. So this is a crucial element for the versatiity of the Asana Python API.

There was one thread here

which proposes a solution, but unfortunately this doesnt work for me even after trying to reconstruct this solution in my application.

For permanently running applications i still get the error message:

Exception in thread Thread-21:
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "C:\Users\John\Desktop\agri\asana_project\agsana\agsana\event_handler.py", line 96, in run
    event = self.client.events.get(
  File "C:\Users\John\Desktop\agri\asana_project\agsana\agsana\venv\lib\site-packages\asana\resources\events.py", line 12, in get
    return self.client.get('/events', params, **options)
  File "C:\Users\John\Desktop\agri\asana_project\agsana\agsana\venv\lib\site-packages\asana\client.py", line 173, in get
    return self.request('get', path, params=query, **options)
  File "C:\Users\John\Desktop\agri\asana_project\agsana\agsana\venv\lib\site-packages\asana\client.py", line 91, in request
    raise STATUS_MAP[response.status_code](response)
asana.error.NoAuthorizationError: No Authorization: The bearer token has expired. If you have a refresh token, please use it to request a new bearer token, otherwise allow the user to re-authenticate.
Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "C:\Users\John\Desktop\agri\asana_project\agsana\agsana\event_handler.py", line 96, in run
    event = self.client.events.get(
  File "C:\Users\John\Desktop\agri\asana_project\agsana\agsana\venv\lib\site-packages\asana\resources\events.py", line 12, in get
    return self.client.get('/events', params, **options)
  File "C:\Users\John\Desktop\agri\asana_project\agsana\agsana\venv\lib\site-packages\asana\client.py", line 173, in get
    return self.request('get', path, params=query, **options)
  File "C:\Users\John\Desktop\agri\asana_project\agsana\agsana\venv\lib\site-packages\asana\client.py", line 91, in request
    raise STATUS_MAP[response.status_code](response)
asana.error.NoAuthorizationError: No Authorization: The bearer token has expired. If you have a refresh token, please use it to request a new bearer token, otherwise allow the user to re-authenticate.

I currently use the auto update approach described in the linked thread above, but it doesn’t work.
According to Oauth specification there are multiple ways to achieve this but none of them seems to work in my application.

My proposal is to find a definite solution for all the Python devs out there who use asana python library. Authentication should be more straight forward so we can focus on application logic.
Please, asana devs, as well as users who have a working solution for this common issue, post your approach here so we can all solve this cumbersome problem with the asana python api.

Plesase do not post solutions involving the PAT method since for some applications does not work, only Oauth based workflow!