requests-oauthlib
requests-oauthlib copied to clipboard
Automatic token refresh on error
Sometimes token can be revoked or otherwise made unusable on servers for various reasons without client knowing. It would be nice if request()
could intercept such a specific error (recognizing it by status code and/or error code in the body, both configurable in arguments) and automatically attempt to refresh the token and retry (once) before failing.
Yeah, this is a good idea. Unfortunately, it probably requires a pretty substantial interface change to get it to work in a way that is nice. I don't really want to just shove a bunch of arguments into most methods, nor do I want to put them in a constructor: eventually a long list of special-case arguments just becomes nasty to handle.
It might be better to create a RefreshPolicy
object that can handle stuff like this instead.
This is quite an issue for us too. We have a background task that synchronises information with Exact Online, but due to the token becoming outdated, the user needs to manually re-authenticate quite often. I'm not 100% sure this is caused by this issue or by Exact being pig-headed, but having a way to get more information about what's happening would be useful.