about summary refs log tree commit diff
path: root/gn2/wqflask/oauth2
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-05-14 09:30:15 +0300
committerFrederick Muriuki Muriithi2024-05-14 09:31:30 +0300
commit8a4ab36a4691db03f731f918b7c4e6ff859157ee (patch)
tree83ce679a2834fedc70e152df331aa5e32aced77a /gn2/wqflask/oauth2
parentd80bf00d16048c0f1dbc5635ce6bf52411d44346 (diff)
downloadgenenetwork2-8a4ab36a4691db03f731f918b7c4e6ff859157ee.tar.gz
Consistently use the same OAuthSession client
Diffstat (limited to 'gn2/wqflask/oauth2')
-rw-r--r--gn2/wqflask/oauth2/checks.py12
-rw-r--r--gn2/wqflask/oauth2/client.py10
2 files changed, 9 insertions, 13 deletions
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: