I wrote a python script using the official python wrapper for the asana API. Authentication and all the others things i planed to do are working very well, but when my token expires after 60 minutes I struggle to detect that. Is there a method to check if authentication is still valid?
client.session.authorized
Seems not to be updated when the 60 minutes expire.
I think the best solution is the third option, automatic refreshing. With our lib in itâs current state, you should be able to do it with something like this:
I try that with a token generated from a previous session. If the token doesnât exist, then I prompt the user to authorize the app and save the token for subsequent sessions.
You need to pass the auto_refresh_kwargs so that requests_oauthlib makes the correct POST request to https://app.asana.com/-/oauth_token.
Itâs also important to note that your code has to keep track of the tokenâs moment of expiration and change token[âexpires_inâ] accordingly. The auto refresh is only triggered when that value is negative.
This took me a long time to figure out! Hopefully it helps someone!
I am right now struggling with this. Why is this not part of the python library yet? This should be HIGH priority since many backend applications will need this. I canât believe this is not implemented yet
Do you have to invoke some library function for the auto refresh or just set the token[âexpires_inâ] of the âtokenâ variable in the code to -10 with a scheduled function that does this, say, every 3500 seconds?