Skip to content

Commit e6f4516

Browse files
fix: server error when redirect_uri_info is not passed in the sign_in_up API
1 parent 32d307b commit e6f4516

File tree

2 files changed

+75
-12
lines changed

2 files changed

+75
-12
lines changed

supertokens_python/recipe/thirdparty/api/signinup.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ async def handle_sign_in_up_api(
4242
if third_party_id is None or not isinstance(third_party_id, str):
4343
raise_bad_input_exception("Please provide the thirdPartyId in request body")
4444

45-
redirect_uri_info = body.get("redirectURIInfo")
46-
oauth_tokens = body.get("oAuthTokens")
47-
48-
if redirect_uri_info is not None:
49-
if redirect_uri_info.get("redirectURIOnProviderDashboard") is None:
45+
oauth_tokens = None
46+
redirect_uri_info = None
47+
if body.get("redirectURIInfo") is not None:
48+
if body.get("redirectURIInfo").get("redirectURIOnProviderDashboard") is None:
5049
raise_bad_input_exception(
5150
"Please provide the redirectURIOnProviderDashboard in request body"
5251
)
53-
elif oauth_tokens is not None:
54-
pass # Nothing to do here
52+
redirect_uri_info = body.get("redirectURIInfo")
53+
elif body.get("oAuthTokens") is not None:
54+
oauth_tokens = body.get("oAuthTokens")
5555
else:
5656
raise_bad_input_exception(
5757
"Please provide one of redirectURIInfo or oAuthTokens in the request body"
@@ -71,15 +71,18 @@ async def handle_sign_in_up_api(
7171

7272
provider = provider_response
7373

74-
result = await api_implementation.sign_in_up_post(
75-
provider=provider,
76-
redirect_uri_info=RedirectUriInfo(
74+
if redirect_uri_info is not None:
75+
redirect_uri_info = RedirectUriInfo(
7776
redirect_uri_on_provider_dashboard=redirect_uri_info.get(
7877
"redirectURIOnProviderDashboard"
7978
),
8079
redirect_uri_query_params=redirect_uri_info.get("redirectURIQueryParams"),
8180
pkce_code_verifier=redirect_uri_info.get("pkceCodeVerifier"),
82-
),
81+
)
82+
83+
result = await api_implementation.sign_in_up_post(
84+
provider=provider,
85+
redirect_uri_info=redirect_uri_info,
8386
oauth_tokens=oauth_tokens,
8487
tenant_id=tenant_id,
8588
api_options=api_options,

tests/thirdparty/test_thirdparty.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def fastapi_client():
4949
app = FastAPI()
5050
app.add_middleware(get_middleware())
5151

52-
return TestClient(app, raise_server_exceptions=False)
52+
return TestClient(app, raise_server_exceptions=True)
5353

5454

5555
async def test_thirdpary_parsing_works(fastapi_client: TestClient):
@@ -268,3 +268,63 @@ async def test_signinup_works_when_validate_access_token_does_not_throw(
268268
assert res.status_code == 200
269269
assert access_token_validated is True
270270
assert res.json()["status"] == "OK"
271+
272+
273+
async def test_signinup_android_without_redirect_uri(
274+
fastapi_client: TestClient, mocker: MockerFixture
275+
):
276+
time = str(datetime.datetime.now())
277+
mocker.patch(
278+
"supertokens_python.recipe.thirdparty.providers.custom.get_supertokens_user_info_result_from_raw_user_info",
279+
return_value=UserInfo(
280+
"" + time,
281+
UserInfoEmail(f"johndoeprovidertest+{time}@supertokens.com", True),
282+
RawUserInfoFromProvider({}, {}),
283+
),
284+
)
285+
st_init_args = {
286+
**st_init_common_args,
287+
"recipe_list": [
288+
session.init(),
289+
thirdpartyemailpassword.init(
290+
providers=[
291+
ProviderInput(
292+
config=ProviderConfig(
293+
third_party_id="custom",
294+
clients=[
295+
ProviderClientConfig(
296+
client_id="test",
297+
client_secret="test-secret",
298+
scope=["profile", "email"],
299+
client_type="android",
300+
),
301+
],
302+
authorization_endpoint="https://example.com/oauth/authorize",
303+
authorization_endpoint_query_params={
304+
"response_type": "token", # Changing an existing parameter
305+
"response_mode": "form", # Adding a new parameter
306+
"scope": None, # Removing a parameter
307+
},
308+
token_endpoint="https://example.com/oauth/token",
309+
),
310+
)
311+
]
312+
),
313+
],
314+
}
315+
init(**st_init_args) # type: ignore
316+
start_st()
317+
318+
res = fastapi_client.post(
319+
"/auth/signinup",
320+
json={
321+
"thirdPartyId": "custom",
322+
"clientType": "android",
323+
"oAuthTokens": {
324+
"access_token": "accesstoken",
325+
"id_token": "idtoken",
326+
},
327+
},
328+
)
329+
assert res.status_code == 200
330+
assert res.json()["status"] == "OK"

0 commit comments

Comments
 (0)