From 8a4ab36a4691db03f731f918b7c4e6ff859157ee Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 14 May 2024 09:30:15 +0300 Subject: Consistently use the same OAuthSession client --- gn2/wqflask/oauth2/checks.py | 12 +++++++----- gn2/wqflask/oauth2/client.py | 10 ++-------- 2 files changed, 9 insertions(+), 13 deletions(-) (limited to 'gn2/wqflask/oauth2') 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: -- cgit v1.2.3