aboutsummaryrefslogtreecommitdiff
path: root/uploader/oauth2/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/oauth2/client.py')
-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__)