about summary refs log tree commit diff
path: root/gn2/wqflask
diff options
context:
space:
mode:
Diffstat (limited to 'gn2/wqflask')
-rw-r--r--gn2/wqflask/__init__.py7
-rw-r--r--gn2/wqflask/oauth2/checks.py12
-rw-r--r--gn2/wqflask/oauth2/client.py10
3 files changed, 11 insertions, 18 deletions
diff --git a/gn2/wqflask/__init__.py b/gn2/wqflask/__init__.py
index 4dee4fea..e3708b0b 100644
--- a/gn2/wqflask/__init__.py
+++ b/gn2/wqflask/__init__.py
@@ -13,7 +13,6 @@ import redis
 import jinja2
 from flask_session import Session
 from authlib.jose import JsonWebKey
-from authlib.integrations.requests_client import OAuth2Session
 from flask import g, Flask, flash, session, url_for, redirect, current_app
 
 
@@ -159,11 +158,9 @@ def before_request():
 
     token = session.get("oauth2_token", False)
     if token and not bool(session.get("user_details", False)):
+        from gn2.wqflask.oauth2.client import oauth2_client
         config = current_app.config
-        client = OAuth2Session(
-            config["OAUTH2_CLIENT_ID"], config["OAUTH2_CLIENT_SECRET"],
-            token=token)
-        resp = client.get(
+        resp = oauth2_client().client.get(
             urljoin(config["GN_SERVER_URL"], "oauth2/user"))
         user_details = resp.json()
         session["user_details"] = user_details
diff --git a/gn2/wqflask/oauth2/checks.py b/gn2/wqflask/oauth2/checks.py
index d4025ffd..7f33348e 100644
--- a/gn2/wqflask/oauth2/checks.py
+++ b/gn2/wqflask/oauth2/checks.py
@@ -7,9 +7,13 @@ from flask import (
     flash, request, redirect, session as flask_session)
 
 from . import session
-from .client import (
-    authserver_uri, oauth2_clientid, oauth2_clientsecret, oauth2_get)
 from .session import clear_session_info
+from .client import (
+    oauth2_get,
+    oauth2_client,
+    authserver_uri,
+    oauth2_clientid,
+    oauth2_clientsecret)
 
 
 def require_oauth2(func):
@@ -26,9 +30,7 @@ def require_oauth2(func):
             return redirect("/")
 
         def __with_token__(token):
-            client = OAuth2Session(
-                oauth2_clientid(), oauth2_clientsecret(), token=token)
-            resp = client.get(
+            resp = oauth2_client().get(
                 urljoin(authserver_uri(), "auth/user/"))
             user_details = resp.json()
             if not user_details.get("error", False):
diff --git a/gn2/wqflask/oauth2/client.py b/gn2/wqflask/oauth2/client.py
index f4ad4f00..75e438cc 100644
--- a/gn2/wqflask/oauth2/client.py
+++ b/gn2/wqflask/oauth2/client.py
@@ -73,10 +73,7 @@ def __no_token__(_err) -> Left:
 def oauth2_get(uri_path: str, data: dict = {},
                jsonify_p: bool = False, **kwargs) -> Either:
     def __get__(token) -> Either:
-        client = OAuth2Session(
-            oauth2_clientid(), oauth2_clientsecret(),
-            token=token, scope=SCOPE)
-        resp = client.get(
+        resp = oauth2_client().get(
             urljoin(authserver_uri(), uri_path),
             data=data,
             **kwargs)
@@ -93,10 +90,7 @@ def oauth2_post(
         uri_path: str, data: Optional[dict] = None, json: Optional[dict] = None,
         **kwargs) -> Either:
     def __post__(token) -> Either:
-        client = OAuth2Session(
-            oauth2_clientid(), oauth2_clientsecret(),
-            token=token, scope=SCOPE)
-        resp = client.post(
+        resp = oauth2_client().post(
             urljoin(authserver_uri(), uri_path), data=data, json=json,
             **kwargs)
         if resp.status_code == 200: