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

TokenExpiredError -- token not refreshing? #3

Open
chrisroat opened this issue Mar 5, 2022 · 3 comments
Open

TokenExpiredError -- token not refreshing? #3

chrisroat opened this issue Mar 5, 2022 · 3 comments

Comments

@chrisroat
Copy link

When I first run this example and login, it works correctly - I can login and it reports my email address. If I refresh the page a few hours later, I get a TokenExpiredError.

I am using Chrome on a Mac, turned off all extensions, and allow all cookies.

Chrome: Version 98.0.4758.109 (Official Build) (x86_64)

MacOS: 12.2.1

Command:

FLASK_APP=google.py FLASK_ENV=development flask run
`pip freeze` output
blinker==1.4
certifi==2021.10.8
charset-normalizer==2.0.12
click==8.0.4
Flask==2.0.3
Flask-Dance==5.1.0
gunicorn==20.1.0
idna==3.3
itsdangerous==2.1.0
Jinja2==3.0.3
MarkupSafe==2.1.0
oauthlib==3.2.0
python-dotenv==0.19.2
requests==2.27.1
requests-oauthlib==1.3.1
urllib3==1.26.8
URLObject==2.4.3
Werkzeug==2.0.3
traceback
Traceback (most recent call last):
  File "/Users/chrisroat/flask-dance-google/venv/lib/python3.9/site-packages/flask/app.py", line 2091, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/chrisroat/flask-dance-google/venv/lib/python3.9/site-packages/flask/app.py", line 2076, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/chrisroat/flask-dance-google/venv/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/chrisroat/flask-dance-google/venv/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/chrisroat/flask-dance-google/venv/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/chrisroat/flask-dance-google/venv/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/Users/chrisroat/flask-dance-google/google.py", line 16, in index
    resp = google.get("/oauth2/v1/userinfo")
  File "/Users/chrisroat/flask-dance-google/venv/lib/python3.9/site-packages/requests/sessions.py", line 542, in get
    return self.request('GET', url, **kwargs)
  File "/Users/chrisroat/flask-dance-google/venv/lib/python3.9/site-packages/flask_dance/consumer/requests.py", line 192, in request
    return super().request(
  File "/Users/chrisroat/flask-dance-google/venv/lib/python3.9/site-packages/requests_oauthlib/oauth2_session.py", line 483, in request
    url, headers, data = self._client.add_token(
  File "/Users/chrisroat/flask-dance-google/venv/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 217, in add_token
    raise TokenExpiredError()
oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired)
@gg4u
Copy link

gg4u commented Mar 28, 2022

Got the same error!

Have you maybe found a solution, @chrisroat ?

@chrisroat
Copy link
Author

I found you need to catch the error and handle it, something like:

singingwolfboy/flask-dance#35 (comment)

@holdenweb
Copy link

See singingwolfboy/flask-dance#35 (comment) - deleting expired tokens from the flask session in a before_request function appears to do the trick!

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

3 participants