Skip to content

Commit 97f8bd5

Browse files
Merge pull request #402 from supertokens/fix/tp-rework-user-password-put
fix: Fix tenant id being passed in the wrong order for password update functions
2 parents 488e367 + f95a9d1 commit 97f8bd5

File tree

19 files changed

+79
-113
lines changed

19 files changed

+79
-113
lines changed

supertokens_python/recipe/dashboard/api/userdetails/user_password_put.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async def reset_password(
106106
)
107107

108108
password_reset_token = await create_reset_password_token(
109-
user_id, tenant_id, user_context
109+
tenant_id, user_id, user_context
110110
)
111111

112112
if isinstance(password_reset_token, CreateResetPasswordWrongUserIdError):
@@ -115,7 +115,7 @@ async def reset_password(
115115
raise Exception("Should never come here")
116116

117117
password_reset_response = await reset_password_using_token(
118-
password_reset_token.token, new_password, tenant_id, user_context
118+
tenant_id, password_reset_token.token, new_password, user_context
119119
)
120120

121121
if isinstance(

supertokens_python/recipe/multitenancy/api/implementation.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ async def login_methods_get(
4040
api_options: APIOptions,
4141
user_context: Dict[str, Any],
4242
) -> Union[LoginMethodsGetOkResult, GeneralErrorResponse]:
43-
tenant_config_res = await api_options.recipe_implementation.get_tenant(
43+
44+
tenant_config = await api_options.recipe_implementation.get_tenant(
4445
tenant_id, user_context
4546
)
4647

48+
if tenant_config is None:
49+
raise Exception("Tenant not found")
50+
4751
provider_inputs_from_static = api_options.static_third_party_providers
48-
provider_configs_from_core = tenant_config_res.third_party.providers
52+
provider_configs_from_core = tenant_config.third_party.providers
4953

5054
merged_providers = merge_providers_from_core_and_static(
5155
provider_configs_from_core, provider_inputs_from_static
@@ -61,24 +65,22 @@ async def login_methods_get(
6165
client_type,
6266
user_context,
6367
)
64-
final_provider_list.append(
65-
ThirdPartyProvider(
66-
provider_instance.id, provider_instance.config.name
67-
)
68-
)
69-
except Exception as e:
70-
if isinstance(e, ClientTypeNotFoundError):
71-
continue
72-
raise e
68+
69+
if provider_instance is None:
70+
raise Exception("Should never come here")
71+
72+
except ClientTypeNotFoundError:
73+
continue
74+
final_provider_list.append(
75+
ThirdPartyProvider(provider_instance.id, provider_instance.config.name)
76+
)
7377

7478
return LoginMethodsGetOkResult(
7579
email_password=LoginMethodEmailPassword(
76-
tenant_config_res.emailpassword.enabled
77-
),
78-
passwordless=LoginMethodPasswordless(
79-
tenant_config_res.passwordless.enabled
80+
tenant_config.emailpassword.enabled
8081
),
82+
passwordless=LoginMethodPasswordless(tenant_config.passwordless.enabled),
8183
third_party=LoginMethodThirdParty(
82-
tenant_config_res.third_party.enabled, final_provider_list
84+
tenant_config.third_party.enabled, final_provider_list
8385
),
8486
)

supertokens_python/recipe/multitenancy/asyncio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def delete_tenant(
6161

6262
async def get_tenant(
6363
tenant_id: str, user_context: Optional[Dict[str, Any]] = None
64-
) -> GetTenantOkResult:
64+
) -> Optional[GetTenantOkResult]:
6565
if user_context is None:
6666
user_context = {}
6767
recipe = MultitenancyRecipe.get_instance()

supertokens_python/recipe/multitenancy/interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ async def delete_tenant(
216216
@abstractmethod
217217
async def get_tenant(
218218
self, tenant_id: str, user_context: Dict[str, Any]
219-
) -> GetTenantOkResult:
219+
) -> Optional[GetTenantOkResult]:
220220
pass
221221

222222
@abstractmethod

supertokens_python/recipe/multitenancy/recipe.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from ...post_init_callbacks import PostSTInitCallbacks
2828

2929
from .interfaces import (
30-
APIInterface,
3130
APIOptions,
3231
TypeGetAllowedDomainsForTenantId,
3332
)
@@ -42,19 +41,12 @@
4241

4342
from supertokens_python.normalised_url_path import NormalisedURLPath
4443
from supertokens_python.querier import Querier
45-
from supertokens_python.types import GeneralErrorResponse
44+
from supertokens_python.recipe.multitenancy.api.implementation import APIImplementation
4645

4746

4847
from .api import handle_login_methods_api
4948
from .constants import LOGIN_METHODS
5049
from .exceptions import MultitenancyError
51-
from .interfaces import (
52-
LoginMethodsGetOkResult,
53-
ThirdPartyProvider,
54-
LoginMethodEmailPassword,
55-
LoginMethodPasswordless,
56-
LoginMethodThirdParty,
57-
)
5850
from .utils import (
5951
InputOverrideConfig,
6052
validate_and_normalise_user_input,
@@ -196,58 +188,6 @@ def reset():
196188
MultitenancyRecipe.__instance = None
197189

198190

199-
class APIImplementation(APIInterface):
200-
async def login_methods_get(
201-
self,
202-
tenant_id: str,
203-
client_type: Optional[str],
204-
api_options: APIOptions,
205-
user_context: Dict[str, Any],
206-
) -> Union[LoginMethodsGetOkResult, GeneralErrorResponse]:
207-
from supertokens_python.recipe.thirdparty.providers.config_utils import (
208-
find_and_create_provider_instance,
209-
merge_providers_from_core_and_static,
210-
)
211-
from supertokens_python.recipe.thirdparty.exceptions import (
212-
ClientTypeNotFoundError,
213-
)
214-
215-
tenant_config = await api_options.recipe_implementation.get_tenant(
216-
tenant_id, user_context
217-
)
218-
219-
provider_inputs_from_static = api_options.static_third_party_providers
220-
provider_configs_from_core = tenant_config.third_party.providers
221-
222-
merged_providers = merge_providers_from_core_and_static(
223-
provider_configs_from_core, provider_inputs_from_static
224-
)
225-
226-
final_provider_list: List[ThirdPartyProvider] = []
227-
228-
for provider_input in merged_providers:
229-
try:
230-
provider_instance = await find_and_create_provider_instance(
231-
merged_providers,
232-
provider_input.config.third_party_id,
233-
client_type,
234-
user_context,
235-
)
236-
except ClientTypeNotFoundError:
237-
continue
238-
final_provider_list.append(
239-
ThirdPartyProvider(provider_instance.id, provider_instance.config.name)
240-
)
241-
242-
return LoginMethodsGetOkResult(
243-
LoginMethodEmailPassword(tenant_config.emailpassword.enabled),
244-
LoginMethodPasswordless(tenant_config.passwordless.enabled),
245-
LoginMethodThirdParty(
246-
tenant_config.third_party.enabled, final_provider_list
247-
),
248-
)
249-
250-
251191
class AllowedDomainsClaimClass(PrimitiveArrayClaim[List[str]]):
252192
def __init__(self):
253193
default_max_age_in_sec = 60 * 60

supertokens_python/recipe/multitenancy/recipe_implementation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,14 @@ async def delete_tenant(
159159

160160
async def get_tenant(
161161
self, tenant_id: Optional[str], user_context: Dict[str, Any]
162-
) -> GetTenantOkResult:
162+
) -> Optional[GetTenantOkResult]:
163163
res = await self.querier.send_get_request(
164164
NormalisedURLPath(f"{tenant_id}/recipe/multitenancy/tenant"),
165165
)
166166

167+
if res["status"] == "TENANT_NOT_FOUND_ERROR":
168+
return None
169+
167170
tenant_config = parse_tenant_config(res)
168171

169172
return GetTenantOkResult(

supertokens_python/recipe/thirdparty/api/authorisation_url.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
if TYPE_CHECKING:
2020
from supertokens_python.recipe.thirdparty.interfaces import APIOptions, APIInterface
2121

22-
from supertokens_python.exceptions import raise_bad_input_exception
22+
from supertokens_python.exceptions import raise_bad_input_exception, BadInputError
2323
from supertokens_python.utils import send_200_response
2424

2525

@@ -53,7 +53,12 @@ async def handle_authorisation_url_api(
5353
user_context=user_context,
5454
)
5555

56-
provider = provider_response.provider
56+
if provider_response is None:
57+
raise BadInputError(
58+
f"the provider {third_party_id} could not be found in the configuration"
59+
)
60+
61+
provider = provider_response
5762
result = await api_implementation.authorisation_url_get(
5863
provider=provider,
5964
redirect_uri_on_provider_dashboard=redirect_uri_on_provider_dashboard,

supertokens_python/recipe/thirdparty/api/signinup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
if TYPE_CHECKING:
2020
from supertokens_python.recipe.thirdparty.interfaces import APIOptions, APIInterface
2121

22-
from supertokens_python.exceptions import raise_bad_input_exception
22+
from supertokens_python.exceptions import raise_bad_input_exception, BadInputError
2323
from supertokens_python.utils import send_200_response
2424

2525

@@ -64,7 +64,12 @@ async def handle_sign_in_up_api(
6464
user_context=user_context,
6565
)
6666

67-
provider = provider_response.provider
67+
if provider_response is None:
68+
raise BadInputError(
69+
f"the provider {third_party_id} could not be found in the configuration"
70+
)
71+
72+
provider = provider_response
6873

6974
result = await api_implementation.sign_in_up_post(
7075
provider=provider,

supertokens_python/recipe/thirdparty/interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async def get_provider(
114114
client_type: Optional[str],
115115
tenant_id: str,
116116
user_context: Dict[str, Any],
117-
) -> GetProviderOkResult:
117+
) -> Optional[Provider]:
118118
pass
119119

120120

supertokens_python/recipe/thirdparty/providers/config_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,11 @@ async def find_and_create_provider_instance(
262262
third_party_id: str,
263263
client_type: Optional[str],
264264
user_context: Dict[str, Any],
265-
) -> Provider:
265+
) -> Optional[Provider]:
266266
for provider_input in providers:
267267
if provider_input.config.third_party_id == third_party_id:
268268
provider_instance = create_provider(provider_input)
269269
await fetch_and_set_config(provider_instance, client_type, user_context)
270270
return provider_instance
271271

272-
raise Exception(
273-
f"the provider {third_party_id} could not be found in the configuration"
274-
)
272+
return None

0 commit comments

Comments
 (0)