diff options
Diffstat (limited to 'gn2/wqflask')
-rw-r--r-- | gn2/wqflask/oauth2/checks.py | 13 | ||||
-rw-r--r-- | gn2/wqflask/oauth2/client.py | 13 |
2 files changed, 14 insertions, 12 deletions
diff --git a/gn2/wqflask/oauth2/checks.py b/gn2/wqflask/oauth2/checks.py index 1d355ed8..070e956d 100644 --- a/gn2/wqflask/oauth2/checks.py +++ b/gn2/wqflask/oauth2/checks.py @@ -7,17 +7,8 @@ from flask import ( flash, request, url_for, redirect, current_app, session as flask_session) from . import session -from .client import authserver_uri, oauth2_clientid, oauth2_clientsecret - -def user_logged_in(): - """Check whether the user has logged in.""" - suser = session.session_info()["user"] - if suser["logged_in"]: - if session.expired(): - session.clear_session_info() - return False - return suser["token"].is_right() - return False +from .client import ( + authserver_uri, user_logged_in, oauth2_clientid, oauth2_clientsecret) def require_oauth2(func): """Decorator for ensuring user is logged in.""" diff --git a/gn2/wqflask/oauth2/client.py b/gn2/wqflask/oauth2/client.py index b538491b..4e2c67f2 100644 --- a/gn2/wqflask/oauth2/client.py +++ b/gn2/wqflask/oauth2/client.py @@ -11,7 +11,6 @@ from pymonad.either import Left, Right, Either from authlib.integrations.requests_client import OAuth2Session from gn2.wqflask.oauth2 import session -from gn2.wqflask.oauth2.checks import user_logged_in from gn2.wqflask.external_errors import ExternalRequestError SCOPE = ("profile group role resource register-client user masquerade " @@ -29,6 +28,18 @@ def oauth2_clientsecret(): """Return the client secret.""" return app.config["OAUTH2_CLIENT_SECRET"] + +def user_logged_in(): + """Check whether the user has logged in.""" + suser = session.session_info()["user"] + if suser["logged_in"]: + if session.expired(): + session.clear_session_info() + return False + return suser["token"].is_right() + return False + + def oauth2_client(): def __client__(token) -> OAuth2Session: return OAuth2Session( |