Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to refresh the token in requests_oauthlib? #434

Open
pghole opened this issue Jan 5, 2021 · 0 comments
Open

How to refresh the token in requests_oauthlib? #434

pghole opened this issue Jan 5, 2021 · 0 comments

Comments

@pghole
Copy link

pghole commented Jan 5, 2021

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant