Skip to content
26 changes: 13 additions & 13 deletions supertokens_python/recipe/thirdparty/providers/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ async def exchange_auth_code_for_oauth_tokens(
access_token_params["redirect_uri"] = DEV_OAUTH_REDIRECT_URL
# Transformation needed for dev keys END

return await do_post_request(token_api_url, access_token_params)
_, body = await do_post_request(token_api_url, access_token_params)
return body

async def get_user_info(
self, oauth_tokens: Dict[str, Any], user_context: Dict[str, Any]
Expand Down Expand Up @@ -412,21 +413,20 @@ async def get_user_info(
headers: Dict[str, str] = {"Authorization": f"Bearer {access_token}"}
query_params: Dict[str, str] = {}

if self.config.user_info_endpoint is not None:
if self.config.user_info_endpoint_headers is not None:
headers = merge_into_dict(
self.config.user_info_endpoint_headers, headers
)

if self.config.user_info_endpoint_query_params is not None:
query_params = merge_into_dict(
self.config.user_info_endpoint_query_params, query_params
)
if self.config.user_info_endpoint_headers is not None:
headers = merge_into_dict(
self.config.user_info_endpoint_headers, headers
)

raw_user_info_from_provider.from_user_info_api = await do_get_request(
self.config.user_info_endpoint, query_params, headers
if self.config.user_info_endpoint_query_params is not None:
query_params = merge_into_dict(
self.config.user_info_endpoint_query_params, query_params
)

raw_user_info_from_provider.from_user_info_api = await do_get_request(
self.config.user_info_endpoint, query_params, headers
)

user_info_result = get_supertokens_user_info_result_from_raw_user_info(
self.config, raw_user_info_from_provider
)
Expand Down
5 changes: 2 additions & 3 deletions supertokens_python/recipe/thirdparty/providers/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ async def validate_access_token(
"Content-Type": "application/json",
}

try:
body = await do_post_request(url, {"access_token": access_token}, headers)
except Exception:
status, body = await do_post_request(url, {"access_token": access_token}, headers)
if status != 200:
raise ValueError("Invalid access token")

if "app" not in body or body["app"].get("client_id") != config.client_id:
Expand Down
3 changes: 2 additions & 1 deletion supertokens_python/recipe/thirdparty/providers/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ async def exchange_auth_code_for_oauth_tokens(

assert self.config.token_endpoint is not None

return await do_post_request(
_, body = await do_post_request(
self.config.token_endpoint,
body_params=twitter_oauth_tokens_params,
headers={"Authorization": f"Basic {auth_token}"},
)
return body


def Twitter(input: ProviderInput) -> Provider: # pylint: disable=redefined-builtin
Expand Down
6 changes: 3 additions & 3 deletions supertokens_python/recipe/thirdparty/providers/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional
from typing import Any, Dict, Optional, Tuple
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what version is Tuple supported in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


from httpx import AsyncClient

Expand Down Expand Up @@ -48,7 +48,7 @@ async def do_post_request(
url: str,
body_params: Optional[Dict[str, str]] = None,
headers: Optional[Dict[str, str]] = None,
) -> Dict[str, Any]:
) -> Tuple[int, Dict[str, Any]]:
if body_params is None:
body_params = {}
if headers is None:
Expand All @@ -62,4 +62,4 @@ async def do_post_request(
log_debug_message(
"Received response with status %s and body %s", res.status_code, res.text
)
return res.json()
return res.status_code, res.json()
5 changes: 5 additions & 0 deletions tests/thirdparty/test_thirdparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

respx_mock = respx.MockRouter

access_token_validated: bool = False


@fixture(scope="function")
async def fastapi_client():
Expand Down Expand Up @@ -145,7 +147,9 @@ async def valid_access_token( # pylint: disable=unused-argument
config: ProviderConfigForClient,
user_context: Optional[Dict[str, Any]],
):
global access_token_validated
if access_token == "accesstoken":
access_token_validated = True
return
raise Exception("Unexpected access token")

Expand Down Expand Up @@ -262,4 +266,5 @@ async def test_signinup_works_when_validate_access_token_does_not_throw(
)

assert res.status_code == 200
assert access_token_validated is True
assert res.json()["status"] == "OK"