requests-oauthlib
requests-oauthlib copied to clipboard
How to refresh the token in requests_oauthlib?
I referred the doc, however I don't see my token getting refreshed automatically and it gives me 401. I don't have any flask server. What am I doing wrong ?
from requests_oauthlib import OAuth2Session
refresh_url = 'https://xmvfs.com/token'
client_id = 'xxx'
extra = {}
token = {
'access_token': 'eswfld123kjhn1v5423',
'refresh_token': 'asdfkljh23490sdf', 'token_type': 'Bearer',
'expires_in': 600 }
def token_saver(token):
pass
client = OAuth2Session(client_id, token=token, auto_refresh_url=refresh_url, auto_refresh_kwargs=extra, token_updater=token_saver)
time.sleep(600) # the token expires after 600 sec.
r = client.get('https://dsfkjjfk.com/efhf') # I get 401
Also, I have a question - let's say my client.get request takes more than 600 sec to return the response. What happens to tokens ? Do I get 401 in between ?