aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/oauth2/session.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn2/wqflask/oauth2/session.py')
-rw-r--r--gn2/wqflask/oauth2/session.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/gn2/wqflask/oauth2/session.py b/gn2/wqflask/oauth2/session.py
index eec48a7f..92181ccf 100644
--- a/gn2/wqflask/oauth2/session.py
+++ b/gn2/wqflask/oauth2/session.py
@@ -22,6 +22,7 @@ class SessionInfo(TypedDict):
user_agent: str
ip_addr: str
masquerade: Optional[UserDetails]
+ refreshing_token: bool
__SESSION_KEY__ = "GN::2::session_info" # Do not use this outside this module!!
@@ -61,7 +62,8 @@ def session_info() -> SessionInfo:
"user_agent": request.headers.get("User-Agent"),
"ip_addr": request.environ.get("HTTP_X_FORWARDED_FOR",
request.remote_addr),
- "masquerading": None
+ "masquerading": None,
+ "token_refreshing": False
}))
@@ -102,3 +104,23 @@ def unset_masquerading():
"user": the_session["masquerading"],
"masquerading": None
})
+
+
+def toggle_token_refreshing():
+ """Toggle the state of the token_refreshing variable."""
+ _session = session_info()
+ return save_session_info({
+ **_session,
+ "token_refreshing": not _session.get("token_refreshing", False)})
+
+
+def is_token_expired():
+ """Check whether the token is expired."""
+ return user_token().either(
+ lambda _no_token: False,
+ lambda token: datetime.now().timestamp() > token["expires_at"])
+
+
+def is_token_refreshing():
+ """Returns whether the token is being refreshed or not."""
+ return session_info().get("token_refreshing", False)