From ac429a65e7f9dd57b54a0fc96d4e494bdb93a61a Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 29 Jul 2024 12:41:45 -0500 Subject: Fix bugs in POST wrapper for OAuth2 client * Call the correct __post__ function * Set up the headers appropriately --- uploader/oauth2/client.py | 19 +++++++++---------- 1 file 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__) -- cgit v1.2.3