aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/wqflask/oauth2/checks.py7
-rw-r--r--wqflask/wqflask/oauth2/session.py9
2 files changed, 15 insertions, 1 deletions
diff --git a/wqflask/wqflask/oauth2/checks.py b/wqflask/wqflask/oauth2/checks.py
index 473bfe23..4abeb279 100644
--- a/wqflask/wqflask/oauth2/checks.py
+++ b/wqflask/wqflask/oauth2/checks.py
@@ -11,7 +11,12 @@ from . import session
def user_logged_in():
"""Check whether the user has logged in."""
suser = session.session_info()["user"]
- return suser["token"].is_right() and suser["logged_in"]
+ if suser["logged_in"]:
+ if session.expired():
+ session.clear_session_info()
+ return False
+ return suser["token"].is_right()
+ return False
def require_oauth2(func):
"""Decorator for ensuring user is logged in."""
diff --git a/wqflask/wqflask/oauth2/session.py b/wqflask/wqflask/oauth2/session.py
index 0e5896d5..2ef534e2 100644
--- a/wqflask/wqflask/oauth2/session.py
+++ b/wqflask/wqflask/oauth2/session.py
@@ -1,5 +1,6 @@
"""Deal with user sessions"""
from uuid import UUID, uuid4
+from datetime import datetime
from typing import Any, Optional, TypedDict
from flask import request, session
@@ -63,6 +64,14 @@ def session_info() -> SessionInfo:
"masquerading": None
}))
+def expired():
+ the_session = session_info()
+ def __expired__(token):
+ return datetime.now() > datetime.fromtimestamp(token["expires_at"])
+ return the_session["user"]["token"].either(
+ lambda left: False,
+ __expired__)
+
def set_user_token(token: str) -> SessionInfo:
"""Set the user's token."""
info = session_info()