Skip to content

Commit 0ba43d4

Browse files
refactor: changed do_post_request() to return status_code
1 parent ab2abbf commit 0ba43d4

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

supertokens_python/recipe/thirdparty/providers/custom.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ async def exchange_auth_code_for_oauth_tokens(
376376
access_token_params["redirect_uri"] = DEV_OAUTH_REDIRECT_URL
377377
# Transformation needed for dev keys END
378378

379-
return await do_post_request(token_api_url, access_token_params)
379+
_, body = await do_post_request(token_api_url, access_token_params)
380+
return body
380381

381382
async def get_user_info(
382383
self, oauth_tokens: Dict[str, Any], user_context: Dict[str, Any]
@@ -412,21 +413,20 @@ async def get_user_info(
412413
headers: Dict[str, str] = {"Authorization": f"Bearer {access_token}"}
413414
query_params: Dict[str, str] = {}
414415

415-
if self.config.user_info_endpoint is not None:
416-
if self.config.user_info_endpoint_headers is not None:
417-
headers = merge_into_dict(
418-
self.config.user_info_endpoint_headers, headers
419-
)
420-
421-
if self.config.user_info_endpoint_query_params is not None:
422-
query_params = merge_into_dict(
423-
self.config.user_info_endpoint_query_params, query_params
424-
)
416+
if self.config.user_info_endpoint_headers is not None:
417+
headers = merge_into_dict(
418+
self.config.user_info_endpoint_headers, headers
419+
)
425420

426-
raw_user_info_from_provider.from_user_info_api = await do_get_request(
427-
self.config.user_info_endpoint, query_params, headers
421+
if self.config.user_info_endpoint_query_params is not None:
422+
query_params = merge_into_dict(
423+
self.config.user_info_endpoint_query_params, query_params
428424
)
429425

426+
raw_user_info_from_provider.from_user_info_api = await do_get_request(
427+
self.config.user_info_endpoint, query_params, headers
428+
)
429+
430430
user_info_result = get_supertokens_user_info_result_from_raw_user_info(
431431
self.config, raw_user_info_from_provider
432432
)

supertokens_python/recipe/thirdparty/providers/github.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ async def validate_access_token(
9696
"Content-Type": "application/json",
9797
}
9898

99-
try:
100-
body = await do_post_request(url, {"access_token": access_token}, headers)
101-
except Exception:
99+
status, body = await do_post_request(url, {"access_token": access_token}, headers)
100+
if status != 200:
102101
raise ValueError("Invalid access token")
103102

104103
if "app" not in body or body["app"].get("client_id") != config.client_id:

supertokens_python/recipe/thirdparty/providers/twitter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ async def exchange_auth_code_for_oauth_tokens(
8484

8585
assert self.config.token_endpoint is not None
8686

87-
return await do_post_request(
87+
_, body = await do_post_request(
8888
self.config.token_endpoint,
8989
body_params=twitter_oauth_tokens_params,
9090
headers={"Authorization": f"Basic {auth_token}"},
9191
)
92+
return body
9293

9394

9495
def Twitter(input: ProviderInput) -> Provider: # pylint: disable=redefined-builtin

supertokens_python/recipe/thirdparty/providers/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Optional
1+
from typing import Any, Dict, Optional, Tuple
22

33
from httpx import AsyncClient
44

@@ -48,7 +48,7 @@ async def do_post_request(
4848
url: str,
4949
body_params: Optional[Dict[str, str]] = None,
5050
headers: Optional[Dict[str, str]] = None,
51-
) -> Dict[str, Any]:
51+
) -> Tuple[int, Dict[str, Any]]:
5252
if body_params is None:
5353
body_params = {}
5454
if headers is None:
@@ -62,4 +62,4 @@ async def do_post_request(
6262
log_debug_message(
6363
"Received response with status %s and body %s", res.status_code, res.text
6464
)
65-
return res.json()
65+
return res.status_code, res.json()

0 commit comments

Comments
 (0)