aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-07-29 12:41:45 -0500
committerFrederick Muriuki Muriithi2024-08-05 09:52:16 -0500
commitac429a65e7f9dd57b54a0fc96d4e494bdb93a61a (patch)
tree38e5b3ab65b4bdd7691bb0e050eac137125a80b1
parenta603fff86dfeb658a39953d12f0404cbd2b2ae87 (diff)
downloadgn-uploader-ac429a65e7f9dd57b54a0fc96d4e494bdb93a61a.tar.gz
Fix bugs in POST wrapper for OAuth2 client
* Call the correct __post__ function * Set up the headers appropriately
-rw-r--r--uploader/oauth2/client.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/uploader/oauth2/client.py b/uploader/oauth2/client.py
index 7204b1e..28464a3 100644
--- a/uploader/oauth2/client.py
+++ b/uploader/oauth2/client.py
@@ -159,6 +159,11 @@ def oauth2_post(url, data=None, json=None, **kwargs):
"""Do a POST request to the authentication/authorisation server."""
def __post__(token) -> Either:
_uri = urljoin(authserver_uri(), url)
+ _headers = ({
+ **kwargs.get("headers", {}),
+ "Content-Type": "application/json"
+ }
+ if bool(json) else kwargs.get("headers", {}))
try:
request_data = {
**(data or {}),
@@ -169,15 +174,9 @@ def oauth2_post(url, data=None, json=None, **kwargs):
resp = oauth2_client().post(
_uri,
data=(request_data if bool(data) else None),
- json=(request_data if json else None),
- **{
- **kwargs,
- "headers": {
- **kwargs.get("headers", {}),
- "Content-Type": "application/json"
- }
- })
- if resp.status_code in requests.SUCCESS_CODES:
+ json=(request_data if bool(json) else None),
+ **{**kwargs, "headers": _headers})
+ if resp.status_code in mrequests.SUCCESS_CODES:
return Right(resp.json())
return Left(resp)
except Exception as exc:
@@ -185,4 +184,4 @@ def oauth2_post(url, data=None, json=None, **kwargs):
_uri,
exc_info=True)
return Left(exc)
- return session.user_token().either(__no_token__, __get__)
+ return session.user_token().either(__no_token__, __post__)