From 0e10bf59972afa5c02af331bf0a2d6720446574b Mon Sep 17 00:00:00 2001 From: KShivendu Date: Thu, 10 Aug 2023 17:00:40 +0530 Subject: [PATCH 1/3] refactor: Make tenant id compulsory in all recipe functions --- supertokens_python/asyncio/__init__.py | 14 +++- .../api/userdetails/user_email_verify_put.py | 4 +- .../user_email_verify_token_post.py | 4 +- .../recipe/dashboard/api/users_get.py | 7 +- .../emailpassword/api/implementation.py | 12 +-- .../recipe/emailpassword/asyncio/__init__.py | 30 +++----- .../recipe/emailpassword/syncio/__init__.py | 28 +++---- .../recipe/emailpassword/types.py | 4 +- .../emailverification/asyncio/__init__.py | 16 ++-- .../emailverification/syncio/__init__.py | 20 ++--- .../recipe/emailverification/types.py | 4 +- .../recipe/multitenancy/api/implementation.py | 2 +- .../recipe/multitenancy/api/login_methods.py | 2 +- .../recipe/multitenancy/asyncio/__init__.py | 12 +-- .../recipe/multitenancy/interfaces.py | 14 ++-- .../recipe/multitenancy/recipe.py | 5 +- .../recipe/multitenancy/syncio/__init__.py | 12 +-- supertokens_python/recipe/openid/recipe.py | 4 +- .../recipe/passwordless/api/implementation.py | 19 ++--- .../recipe/passwordless/asyncio/__init__.py | 72 +++++++----------- .../recipe/passwordless/syncio/__init__.py | 53 ++++++++----- .../recipe/passwordless/types.py | 4 +- .../recipe/session/asyncio/__init__.py | 8 +- .../recipe/session/recipe_implementation.py | 2 +- .../recipe/session/session_functions.py | 5 +- .../recipe/session/syncio/__init__.py | 18 ++--- .../recipe/thirdparty/api/implementation.py | 8 +- .../recipe/thirdparty/asyncio/__init__.py | 16 ++-- .../thirdparty/recipe_implementation.py | 2 +- .../recipe/thirdparty/syncio/__init__.py | 16 ++-- .../asyncio/__init__.py | 32 ++++---- .../thirdpartyemailpassword/interfaces.py | 2 +- .../recipeimplementation/implementation.py | 2 +- .../third_party_recipe_implementation.py | 2 +- .../syncio/__init__.py | 50 ++++++------ .../asyncio/__init__.py | 48 +++++------- .../thirdpartypasswordless/syncio/__init__.py | 76 ++++++++----------- .../recipe/userroles/asyncio/__init__.py | 18 ++--- .../recipe/userroles/syncio/__init__.py | 22 +++--- supertokens_python/supertokens.py | 6 +- supertokens_python/syncio/__init__.py | 4 +- tests/Django/test_django.py | 2 +- tests/Fastapi/test_fastapi.py | 6 +- tests/Flask/test_flask.py | 4 +- tests/auth-react/django3x/polls/views.py | 4 +- tests/auth-react/fastapi-server/app.py | 2 +- tests/auth-react/flask-server/app.py | 2 +- tests/emailpassword/test_emaildelivery.py | 10 +-- tests/emailpassword/test_emailexists.py | 2 +- tests/emailpassword/test_emailverify.py | 20 ++--- tests/emailpassword/test_multitenancy.py | 36 ++++----- tests/emailpassword/test_passwordreset.py | 2 +- tests/emailpassword/test_signin.py | 2 +- .../django2x/polls/views.py | 2 +- .../django3x/polls/views.py | 2 +- .../frontendIntegration/fastapi-server/app.py | 2 +- tests/frontendIntegration/flask-server/app.py | 2 +- tests/jwt/test_get_JWKS.py | 2 +- tests/multitenancy/test_tenants_crud.py | 2 +- tests/passwordless/test_mutlitenancy.py | 24 +++--- .../claims/test_create_new_session.py | 6 +- tests/sessions/claims/test_get_claim_value.py | 4 +- tests/sessions/claims/test_remove_claim.py | 4 +- tests/sessions/claims/test_set_claim_value.py | 4 +- ...test_validate_claims_for_session_handle.py | 2 +- tests/sessions/claims/test_verify_session.py | 4 +- tests/sessions/test_access_token_v3.py | 4 +- tests/sessions/test_auth_mode.py | 2 +- tests/sessions/test_jwks.py | 16 ++-- .../test_supertokens_functions.py | 24 ++++-- tests/test_config.py | 2 +- tests/test_pagination.py | 8 +- tests/test_passwordless.py | 4 +- tests/test_session.py | 12 +-- ...test_thirdpartypasswordless_delete_user.py | 4 +- tests/test_user_context.py | 6 +- tests/thirdparty/test_emaildelivery.py | 20 ++--- tests/thirdparty/test_multitenancy.py | 42 +++++----- .../test_email_delivery.py | 18 ++--- .../test_emaildelivery.py | 22 +++--- tests/useridmapping/create_user_id_mapping.py | 8 +- tests/useridmapping/delete_user_id_mapping.py | 4 +- tests/useridmapping/get_user_id_mapping.py | 2 +- tests/useridmapping/recipe_tests.py | 12 +-- tests/userroles/test_add_role_to_user.py | 14 ++-- tests/userroles/test_claims.py | 24 +++--- tests/userroles/test_delete_role.py | 4 +- tests/userroles/test_get_roles_for_user.py | 4 +- .../test_get_users_that_have_role.py | 6 +- tests/userroles/test_multitenancy.py | 20 ++--- .../test_remove_permissions_from_role.py | 2 +- tests/userroles/test_remove_user_role.py | 12 +-- tests/utils.py | 10 ++- 93 files changed, 544 insertions(+), 593 deletions(-) diff --git a/supertokens_python/asyncio/__init__.py b/supertokens_python/asyncio/__init__.py index ab3b7c89c..ac0a4805d 100644 --- a/supertokens_python/asyncio/__init__.py +++ b/supertokens_python/asyncio/__init__.py @@ -28,29 +28,35 @@ async def get_users_oldest_first( + tenant_id: str, limit: Union[int, None] = None, pagination_token: Union[str, None] = None, include_recipe_ids: Union[None, List[str]] = None, query: Union[None, Dict[str, str]] = None, ) -> UsersResponse: return await Supertokens.get_instance().get_users( - "ASC", limit, pagination_token, include_recipe_ids, query + tenant_id, "ASC", limit, pagination_token, include_recipe_ids, query ) async def get_users_newest_first( + tenant_id: str, limit: Union[int, None] = None, pagination_token: Union[str, None] = None, include_recipe_ids: Union[None, List[str]] = None, query: Union[None, Dict[str, str]] = None, ) -> UsersResponse: return await Supertokens.get_instance().get_users( - "DESC", limit, pagination_token, include_recipe_ids, query + tenant_id, "DESC", limit, pagination_token, include_recipe_ids, query ) -async def get_user_count(include_recipe_ids: Union[None, List[str]] = None) -> int: - return await Supertokens.get_instance().get_user_count(include_recipe_ids) +async def get_user_count( + include_recipe_ids: Union[None, List[str]] = None, tenant_id: Optional[str] = None +) -> int: + return await Supertokens.get_instance().get_user_count( + include_recipe_ids, tenant_id + ) async def delete_user(user_id: str) -> None: diff --git a/supertokens_python/recipe/dashboard/api/userdetails/user_email_verify_put.py b/supertokens_python/recipe/dashboard/api/userdetails/user_email_verify_put.py index 414407056..fd4443ae1 100644 --- a/supertokens_python/recipe/dashboard/api/userdetails/user_email_verify_put.py +++ b/supertokens_python/recipe/dashboard/api/userdetails/user_email_verify_put.py @@ -40,7 +40,7 @@ async def handle_user_email_verify_put( if verified: token_response = await create_email_verification_token( - user_id, tenant_id=tenant_id, user_context=user_context + tenant_id=tenant_id, user_id=user_id, email=None, user_context=user_context ) if isinstance( @@ -49,7 +49,7 @@ async def handle_user_email_verify_put( return UserEmailVerifyPutAPIResponse() verify_response = await verify_email_using_token( - token_response.token, tenant_id, user_context=user_context + tenant_id=tenant_id, token=token_response.token, user_context=user_context ) if isinstance(verify_response, VerifyEmailUsingTokenInvalidTokenError): diff --git a/supertokens_python/recipe/dashboard/api/userdetails/user_email_verify_token_post.py b/supertokens_python/recipe/dashboard/api/userdetails/user_email_verify_token_post.py index 3c0aa705f..b00b0a84e 100644 --- a/supertokens_python/recipe/dashboard/api/userdetails/user_email_verify_token_post.py +++ b/supertokens_python/recipe/dashboard/api/userdetails/user_email_verify_token_post.py @@ -31,7 +31,9 @@ async def handle_email_verify_token_post( "Required parameter 'userId' is missing or has an invalid type" ) - res = await send_email_verification_email(user_id, None, tenant_id, user_context) + res = await send_email_verification_email( + tenant_id=tenant_id, user_id=user_id, email=None, user_context=user_context + ) if isinstance(res, SendEmailVerificationEmailAlreadyVerifiedError): return UserEmailVerifyTokenPostAPIEmailAlreadyVerifiedErrorResponse() diff --git a/supertokens_python/recipe/dashboard/api/users_get.py b/supertokens_python/recipe/dashboard/api/users_get.py index bb6eff621..34a6d83d4 100644 --- a/supertokens_python/recipe/dashboard/api/users_get.py +++ b/supertokens_python/recipe/dashboard/api/users_get.py @@ -15,6 +15,7 @@ import asyncio from typing import TYPE_CHECKING, Any, Awaitable, List, Dict +from typing_extensions import Literal from supertokens_python.supertokens import Supertokens @@ -45,7 +46,7 @@ async def handle_users_get_api( if limit is None: raise_bad_input_exception("Missing required parameter 'limit'") - time_joined_order: str = api_options.request.get_query_param( # type: ignore + time_joined_order: Literal["ASC", "DESC"] = api_options.request.get_query_param( # type: ignore "timeJoinedOrder", "DESC" ) if time_joined_order not in ["ASC", "DESC"]: @@ -54,12 +55,12 @@ async def handle_users_get_api( pagination_token = api_options.request.get_query_param("paginationToken") users_response = await Supertokens.get_instance().get_users( + tenant_id, + time_joined_order=time_joined_order, limit=int(limit), - time_joined_order=time_joined_order, # type: ignore pagination_token=pagination_token, include_recipe_ids=None, query=api_options.request.get_query_params(), - tenant_id=tenant_id, ) # user metadata bulk fetch with batches: diff --git a/supertokens_python/recipe/emailpassword/api/implementation.py b/supertokens_python/recipe/emailpassword/api/implementation.py index 2bac97d26..6ba19be3e 100644 --- a/supertokens_python/recipe/emailpassword/api/implementation.py +++ b/supertokens_python/recipe/emailpassword/api/implementation.py @@ -172,11 +172,11 @@ async def sign_in_post( user = result.user session = await create_new_session( - api_options.request, - user.user_id, + tenant_id=tenant_id, + request=api_options.request, + user_id=user.user_id, access_token_payload={}, session_data_in_database={}, - tenant_id=tenant_id, user_context=user_context, ) return SignInPostOkResult(user, session) @@ -213,11 +213,11 @@ async def sign_up_post( user = result.user session = await create_new_session( - api_options.request, - user.user_id, + tenant_id=tenant_id, + request=api_options.request, + user_id=user.user_id, access_token_payload={}, session_data_in_database={}, - tenant_id=tenant_id, user_context=user_context, ) return SignUpPostOkResult(user, session) diff --git a/supertokens_python/recipe/emailpassword/asyncio/__init__.py b/supertokens_python/recipe/emailpassword/asyncio/__init__.py index e6780a4c6..df0003405 100644 --- a/supertokens_python/recipe/emailpassword/asyncio/__init__.py +++ b/supertokens_python/recipe/emailpassword/asyncio/__init__.py @@ -65,21 +65,17 @@ async def get_user_by_id( async def get_user_by_email( - email: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> Union[User, None]: if user_context is None: user_context = {} return await EmailPasswordRecipe.get_instance().recipe_implementation.get_user_by_email( - email, tenant_id or DEFAULT_TENANT_ID, user_context + tenant_id or DEFAULT_TENANT_ID, email, user_context ) async def create_reset_password_token( - user_id: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, user_id: str, user_context: Union[None, Dict[str, Any]] = None ): if user_context is None: user_context = {} @@ -89,22 +85,22 @@ async def create_reset_password_token( async def reset_password_using_token( + tenant_id: str, token: str, new_password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: user_context = {} return await EmailPasswordRecipe.get_instance().recipe_implementation.reset_password_using_token( - token, new_password, tenant_id or DEFAULT_TENANT_ID, user_context + new_password, tenant_id or DEFAULT_TENANT_ID, token, user_context ) async def sign_in( + tenant_id: str, email: str, password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -115,9 +111,9 @@ async def sign_in( async def sign_up( + tenant_id: str, email: str, password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -139,11 +135,9 @@ async def send_email( async def create_reset_password_link( - user_id: str, - tenant_id: Optional[str] = None, - user_context: Optional[Dict[str, Any]] = None, + tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None ): - token = await create_reset_password_token(user_id, tenant_id, user_context) + token = await create_reset_password_token(tenant_id, user_id, user_context) if isinstance(token, CreateResetPasswordWrongUserIdError): return CreateResetPasswordLinkUknownUserIdError() @@ -159,11 +153,9 @@ async def create_reset_password_link( async def send_reset_password_email( - user_id: str, - tenant_id: Optional[str] = None, - user_context: Optional[Dict[str, Any]] = None, + tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None ): - link = await create_reset_password_link(user_id, tenant_id, user_context) + link = await create_reset_password_link(tenant_id, user_id, user_context) if isinstance(link, CreateResetPasswordLinkUknownUserIdError): return CreateResetPasswordEmailUnknownUserIdError() diff --git a/supertokens_python/recipe/emailpassword/syncio/__init__.py b/supertokens_python/recipe/emailpassword/syncio/__init__.py index bebe5e615..8a7cd833f 100644 --- a/supertokens_python/recipe/emailpassword/syncio/__init__.py +++ b/supertokens_python/recipe/emailpassword/syncio/__init__.py @@ -50,31 +50,31 @@ def get_user_by_id( def get_user_by_email( + tenant_id: str, email: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[None, User]: from supertokens_python.recipe.emailpassword.asyncio import get_user_by_email - return sync(get_user_by_email(email, tenant_id, user_context)) + return sync(get_user_by_email(tenant_id, email, user_context)) def create_reset_password_token( + tenant_id: str, user_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.emailpassword.asyncio import ( create_reset_password_token, ) - return sync(create_reset_password_token(user_id, tenant_id, user_context)) + return sync(create_reset_password_token(tenant_id, user_id, user_context)) def reset_password_using_token( + tenant_id: str, token: str, new_password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.emailpassword.asyncio import ( @@ -82,30 +82,30 @@ def reset_password_using_token( ) return sync( - reset_password_using_token(token, new_password, tenant_id, user_context) + reset_password_using_token(tenant_id, token, new_password, user_context) ) def sign_in( + tenant_id: str, email: str, password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[SignInOkResult, SignInWrongCredentialsError]: from supertokens_python.recipe.emailpassword.asyncio import sign_in - return sync(sign_in(email, password, tenant_id, user_context)) + return sync(sign_in(tenant_id, email, password, user_context)) def sign_up( + tenant_id: str, email: str, password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.emailpassword.asyncio import sign_up - return sync(sign_up(email, password, tenant_id, user_context)) + return sync(sign_up(tenant_id, email, password, user_context)) def send_email( @@ -118,24 +118,24 @@ def send_email( def create_reset_password_link( + tenant_id: str, user_id: str, - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ): from supertokens_python.recipe.emailpassword.asyncio import ( create_reset_password_link, ) - return sync(create_reset_password_link(user_id, tenant_id, user_context)) + return sync(create_reset_password_link(tenant_id, user_id, user_context)) def send_reset_password_email( + tenant_id: str, user_id: str, - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ): from supertokens_python.recipe.emailpassword.asyncio import ( send_reset_password_email, ) - return sync(send_reset_password_email(user_id, tenant_id, user_context)) + return sync(send_reset_password_email(tenant_id, user_id, user_context)) diff --git a/supertokens_python/recipe/emailpassword/types.py b/supertokens_python/recipe/emailpassword/types.py index 9e4f68631..41752c2cd 100644 --- a/supertokens_python/recipe/emailpassword/types.py +++ b/supertokens_python/recipe/emailpassword/types.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. from __future__ import annotations -from typing import Awaitable, Callable, List, TypeVar, Union, Optional +from typing import Awaitable, Callable, List, TypeVar, Union from supertokens_python.ingredients.emaildelivery import EmailDeliveryIngredient from supertokens_python.ingredients.emaildelivery.types import ( @@ -99,7 +99,7 @@ def __init__( self, user: PasswordResetEmailTemplateVarsUser, password_reset_link: str, - tenant_id: Optional[str], + tenant_id: str, ) -> None: self.user = user self.password_reset_link = password_reset_link diff --git a/supertokens_python/recipe/emailverification/asyncio/__init__.py b/supertokens_python/recipe/emailverification/asyncio/__init__.py index 5342f4fcf..abb6fdae9 100644 --- a/supertokens_python/recipe/emailverification/asyncio/__init__.py +++ b/supertokens_python/recipe/emailverification/asyncio/__init__.py @@ -37,9 +37,9 @@ async def create_email_verification_token( + tenant_id: str, user_id: str, email: Optional[str] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[ CreateEmailVerificationTokenOkResult, @@ -63,9 +63,7 @@ async def create_email_verification_token( async def verify_email_using_token( - token: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, token: str, user_context: Union[None, Dict[str, Any]] = None ): if user_context is None: user_context = {} @@ -98,9 +96,9 @@ async def is_email_verified( async def revoke_email_verification_tokens( + tenant_id: str, user_id: str, email: Optional[str] = None, - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ) -> RevokeEmailVerificationTokensOkResult: if user_context is None: @@ -158,9 +156,9 @@ async def send_email( async def create_email_verification_link( + tenant_id: str, user_id: str, email: Optional[str], - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ) -> Union[ CreateEmailVerificationLinkOkResult, @@ -173,7 +171,7 @@ async def create_email_verification_link( app_info = recipe_instance.get_app_info() email_verification_token = await create_email_verification_token( - user_id, email, tenant_id, user_context + tenant_id, user_id, email, user_context ) if isinstance( email_verification_token, CreateEmailVerificationTokenEmailAlreadyVerifiedError @@ -191,9 +189,9 @@ async def create_email_verification_link( async def send_email_verification_email( + tenant_id: str, user_id: str, email: Optional[str], - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ) -> Union[ SendEmailVerificationEmailOkResult, @@ -214,7 +212,7 @@ async def send_email_verification_email( raise Exception("Unknown User ID provided without email") email_verification_link = await create_email_verification_link( - user_id, email, tenant_id, user_context + tenant_id, user_id, email, user_context ) if isinstance( diff --git a/supertokens_python/recipe/emailverification/syncio/__init__.py b/supertokens_python/recipe/emailverification/syncio/__init__.py index 0684d5af6..9621cbec9 100644 --- a/supertokens_python/recipe/emailverification/syncio/__init__.py +++ b/supertokens_python/recipe/emailverification/syncio/__init__.py @@ -19,9 +19,9 @@ def create_email_verification_token( + tenant_id: str, user_id: str, email: Optional[str] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.emailverification.asyncio import ( @@ -29,20 +29,20 @@ def create_email_verification_token( ) return sync( - create_email_verification_token(user_id, email, tenant_id, user_context) + create_email_verification_token(tenant_id, user_id, email, user_context) ) def verify_email_using_token( + tenant_id: str, token: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.emailverification.asyncio import ( verify_email_using_token, ) - return sync(verify_email_using_token(token, tenant_id, user_context)) + return sync(verify_email_using_token(tenant_id, token, user_context)) def is_email_verified( @@ -56,9 +56,9 @@ def is_email_verified( def revoke_email_verification_tokens( + tenant_id: str, user_id: str, email: Optional[str] = None, - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ): from supertokens_python.recipe.emailverification.asyncio import ( @@ -66,7 +66,7 @@ def revoke_email_verification_tokens( ) return sync( - revoke_email_verification_tokens(user_id, email, tenant_id, user_context) + revoke_email_verification_tokens(tenant_id, user_id, email, user_context) ) @@ -90,26 +90,26 @@ def send_email( def create_email_verification_link( + tenant_id: str, user_id: str, email: Optional[str], - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ): from supertokens_python.recipe.emailverification.asyncio import ( create_email_verification_link, ) - return sync(create_email_verification_link(user_id, email, tenant_id, user_context)) + return sync(create_email_verification_link(tenant_id, user_id, email, user_context)) def send_email_verification_email( + tenant_id: str, user_id: str, email: Optional[str], - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ): from supertokens_python.recipe.emailverification.asyncio import ( send_email_verification_email, ) - return sync(send_email_verification_email(user_id, email, tenant_id, user_context)) + return sync(send_email_verification_email(tenant_id, user_id, email, user_context)) diff --git a/supertokens_python/recipe/emailverification/types.py b/supertokens_python/recipe/emailverification/types.py index 43b6f671c..c32b46ddf 100644 --- a/supertokens_python/recipe/emailverification/types.py +++ b/supertokens_python/recipe/emailverification/types.py @@ -13,7 +13,7 @@ # under the License. from __future__ import annotations -from typing import Union, Optional +from typing import Union from supertokens_python.ingredients.emaildelivery import EmailDeliveryIngredient from supertokens_python.ingredients.emaildelivery.types import ( @@ -39,7 +39,7 @@ def __init__( self, user: VerificationEmailTemplateVarsUser, email_verify_link: str, - tenant_id: Optional[str], + tenant_id: str, ) -> None: self.user = user self.email_verify_link = email_verify_link diff --git a/supertokens_python/recipe/multitenancy/api/implementation.py b/supertokens_python/recipe/multitenancy/api/implementation.py index fdac1ca46..431a98fd7 100644 --- a/supertokens_python/recipe/multitenancy/api/implementation.py +++ b/supertokens_python/recipe/multitenancy/api/implementation.py @@ -35,7 +35,7 @@ class APIImplementation(APIInterface): async def login_methods_get( self, - tenant_id: Optional[str], + tenant_id: str, client_type: Optional[str], api_options: APIOptions, user_context: Dict[str, Any], diff --git a/supertokens_python/recipe/multitenancy/api/login_methods.py b/supertokens_python/recipe/multitenancy/api/login_methods.py index 63b20d040..9dc3624a3 100644 --- a/supertokens_python/recipe/multitenancy/api/login_methods.py +++ b/supertokens_python/recipe/multitenancy/api/login_methods.py @@ -23,13 +23,13 @@ async def handle_login_methods_api( api_implementation: APIInterface, + tenant_id: str, api_options: APIOptions, user_context: Dict[str, Any], ): if api_implementation.disable_login_methods_get: return None - tenant_id = api_options.request.get_query_param("tenantId") client_type = api_options.request.get_query_param("clientType") result = await api_implementation.login_methods_get( diff --git a/supertokens_python/recipe/multitenancy/asyncio/__init__.py b/supertokens_python/recipe/multitenancy/asyncio/__init__.py index c7eb43c29..b76d65720 100644 --- a/supertokens_python/recipe/multitenancy/asyncio/__init__.py +++ b/supertokens_python/recipe/multitenancy/asyncio/__init__.py @@ -36,7 +36,7 @@ async def create_or_update_tenant( - tenant_id: Optional[str], + tenant_id: str, config: Optional[TenantConfig], user_context: Optional[Dict[str, Any]] = None, ) -> CreateOrUpdateTenantOkResult: @@ -60,7 +60,7 @@ async def delete_tenant( async def get_tenant( - tenant_id: Optional[str], user_context: Optional[Dict[str, Any]] = None + tenant_id: str, user_context: Optional[Dict[str, Any]] = None ) -> GetTenantOkResult: if user_context is None: user_context = {} @@ -81,7 +81,7 @@ async def list_all_tenants( async def create_or_update_third_party_config( - tenant_id: Optional[str], + tenant_id: str, config: ProviderConfig, skip_validation: Optional[bool] = None, user_context: Optional[Dict[str, Any]] = None, @@ -97,7 +97,7 @@ async def create_or_update_third_party_config( async def delete_third_party_config( - tenant_id: Optional[str], + tenant_id: str, third_party_id: str, user_context: Optional[Dict[str, Any]] = None, ) -> DeleteThirdPartyConfigOkResult: @@ -112,7 +112,7 @@ async def delete_third_party_config( async def associate_user_to_tenant( - tenant_id: Optional[str], + tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None, ) -> Union[ @@ -133,7 +133,7 @@ async def associate_user_to_tenant( async def dissociate_user_from_tenant( - tenant_id: Optional[str], + tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None, ) -> DisassociateUserFromTenantOkResult: diff --git a/supertokens_python/recipe/multitenancy/interfaces.py b/supertokens_python/recipe/multitenancy/interfaces.py index aa3f692e7..dc0708d35 100644 --- a/supertokens_python/recipe/multitenancy/interfaces.py +++ b/supertokens_python/recipe/multitenancy/interfaces.py @@ -199,7 +199,7 @@ async def get_tenant_id( @abstractmethod async def create_or_update_tenant( self, - tenant_id: Optional[str], + tenant_id: str, config: Optional[TenantConfig], user_context: Dict[str, Any], ) -> CreateOrUpdateTenantOkResult: @@ -213,7 +213,7 @@ async def delete_tenant( @abstractmethod async def get_tenant( - self, tenant_id: Optional[str], user_context: Dict[str, Any] + self, tenant_id: str, user_context: Dict[str, Any] ) -> GetTenantOkResult: pass @@ -227,7 +227,7 @@ async def list_all_tenants( @abstractmethod async def create_or_update_third_party_config( self, - tenant_id: Optional[str], + tenant_id: str, config: ProviderConfig, skip_validation: Optional[bool], user_context: Dict[str, Any], @@ -237,7 +237,7 @@ async def create_or_update_third_party_config( @abstractmethod async def delete_third_party_config( self, - tenant_id: Optional[str], + tenant_id: str, third_party_id: str, user_context: Dict[str, Any], ) -> DeleteThirdPartyConfigOkResult: @@ -247,7 +247,7 @@ async def delete_third_party_config( @abstractmethod async def associate_user_to_tenant( self, - tenant_id: Optional[str], + tenant_id: str, user_id: str, user_context: Dict[str, Any], ) -> Union[ @@ -262,7 +262,7 @@ async def associate_user_to_tenant( @abstractmethod async def dissociate_user_from_tenant( self, - tenant_id: Optional[str], + tenant_id: str, user_id: str, user_context: Dict[str, Any], ) -> DisassociateUserFromTenantOkResult: @@ -361,7 +361,7 @@ def __init__(self): @abstractmethod async def login_methods_get( self, - tenant_id: Optional[str], + tenant_id: str, client_type: Optional[str], api_options: APIOptions, user_context: Dict[str, Any], diff --git a/supertokens_python/recipe/multitenancy/recipe.py b/supertokens_python/recipe/multitenancy/recipe.py index d0f063f2a..a2cf56ee6 100644 --- a/supertokens_python/recipe/multitenancy/recipe.py +++ b/supertokens_python/recipe/multitenancy/recipe.py @@ -117,7 +117,7 @@ def get_apis_handled(self) -> List[APIHandled]: async def handle_api_request( self, request_id: str, - tenant_id: Optional[str], + tenant_id: str, request: BaseRequest, path: NormalisedURLPath, method: str, @@ -134,6 +134,7 @@ async def handle_api_request( ) return await handle_login_methods_api( self.api_implementation, + tenant_id, api_options, user_context, ) @@ -198,7 +199,7 @@ def reset(): class APIImplementation(APIInterface): async def login_methods_get( self, - tenant_id: Optional[str], + tenant_id: str, client_type: Optional[str], api_options: APIOptions, user_context: Dict[str, Any], diff --git a/supertokens_python/recipe/multitenancy/syncio/__init__.py b/supertokens_python/recipe/multitenancy/syncio/__init__.py index 4870b8c9b..8567b1917 100644 --- a/supertokens_python/recipe/multitenancy/syncio/__init__.py +++ b/supertokens_python/recipe/multitenancy/syncio/__init__.py @@ -19,7 +19,7 @@ def create_or_update_tenant( - tenant_id: Optional[str], + tenant_id: str, config: Optional[TenantConfig], user_context: Optional[Dict[str, Any]] = None, ): @@ -40,7 +40,7 @@ def delete_tenant(tenant_id: str, user_context: Optional[Dict[str, Any]] = None) return sync(delete_tenant(tenant_id, user_context)) -def get_tenant(tenant_id: Optional[str], user_context: Optional[Dict[str, Any]] = None): +def get_tenant(tenant_id: str, user_context: Optional[Dict[str, Any]] = None): if user_context is None: user_context = {} @@ -59,7 +59,7 @@ def list_all_tenants(user_context: Optional[Dict[str, Any]] = None): def create_or_update_third_party_config( - tenant_id: Optional[str], + tenant_id: str, config: ProviderConfig, skip_validation: Optional[bool] = None, user_context: Optional[Dict[str, Any]] = None, @@ -79,7 +79,7 @@ def create_or_update_third_party_config( def delete_third_party_config( - tenant_id: Optional[str], + tenant_id: str, third_party_id: str, user_context: Optional[Dict[str, Any]] = None, ): @@ -92,7 +92,7 @@ def delete_third_party_config( def associate_user_to_tenant( - tenant_id: Optional[str], + tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None, ): @@ -105,7 +105,7 @@ def associate_user_to_tenant( def dissociate_user_from_tenant( - tenant_id: Optional[str], + tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None, ): diff --git a/supertokens_python/recipe/openid/recipe.py b/supertokens_python/recipe/openid/recipe.py index a17ab53c5..acbe64ade 100644 --- a/supertokens_python/recipe/openid/recipe.py +++ b/supertokens_python/recipe/openid/recipe.py @@ -14,7 +14,7 @@ from __future__ import annotations from os import environ -from typing import TYPE_CHECKING, List, Union, Optional, Any, Dict +from typing import TYPE_CHECKING, List, Union, Any, Dict from supertokens_python.querier import Querier @@ -90,7 +90,7 @@ def get_apis_handled(self) -> List[APIHandled]: async def handle_api_request( self, request_id: str, - tenant_id: Optional[str], + tenant_id: str, request: BaseRequest, path: NormalisedURLPath, method: str, diff --git a/supertokens_python/recipe/passwordless/api/implementation.py b/supertokens_python/recipe/passwordless/api/implementation.py index a7f65a506..ae1c6a0bd 100644 --- a/supertokens_python/recipe/passwordless/api/implementation.py +++ b/supertokens_python/recipe/passwordless/api/implementation.py @@ -289,25 +289,20 @@ async def consume_code_post( ev_instance = EmailVerificationRecipe.get_instance_optional() if ev_instance is not None: token_response = await ev_instance.recipe_implementation.create_email_verification_token( - user.user_id, - user.email, - tenant_id, - user_context, + tenant_id, user.user_id, user.email, user_context ) if isinstance(token_response, CreateEmailVerificationTokenOkResult): await ev_instance.recipe_implementation.verify_email_using_token( - token_response.token, - tenant_id, - user_context, + tenant_id, token_response.token, user_context ) session = await create_new_session( - api_options.request, - user.user_id, - {}, - {}, - tenant_id, + tenant_id=tenant_id, + request=api_options.request, + user_id=user.user_id, + access_token_payload={}, + session_data_in_database={}, user_context=user_context, ) diff --git a/supertokens_python/recipe/passwordless/asyncio/__init__.py b/supertokens_python/recipe/passwordless/asyncio/__init__.py index 16b7523c9..0fecaf7a9 100644 --- a/supertokens_python/recipe/passwordless/asyncio/__init__.py +++ b/supertokens_python/recipe/passwordless/asyncio/__init__.py @@ -11,7 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from typing import Any, Dict, List, Union, Optional +from typing import Any, Dict, List, Union from supertokens_python.recipe.passwordless.interfaces import ( ConsumeCodeExpiredUserInputCodeError, @@ -39,14 +39,12 @@ User, ) -from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID - async def create_code( + tenant_id: str, email: Union[None, str] = None, phone_number: Union[None, str] = None, user_input_code: Union[None, str] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> CreateCodeOkResult: if user_context is None: @@ -55,15 +53,15 @@ async def create_code( email=email, phone_number=phone_number, user_input_code=user_input_code, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) async def create_new_code_for_device( + tenant_id: str, device_id: str, user_input_code: Union[str, None] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[ CreateNewCodeForDeviceOkResult, @@ -75,17 +73,17 @@ async def create_new_code_for_device( return await PasswordlessRecipe.get_instance().recipe_implementation.create_new_code_for_device( device_id=device_id, user_input_code=user_input_code, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) async def consume_code( + tenant_id: str, pre_auth_session_id: str, user_input_code: Union[str, None] = None, device_id: Union[str, None] = None, link_code: Union[str, None] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[ ConsumeCodeOkResult, @@ -100,7 +98,7 @@ async def consume_code( user_input_code=user_input_code, device_id=device_id, link_code=link_code, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -116,31 +114,27 @@ async def get_user_by_id( async def get_user_by_email( - email: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> Union[User, None]: if user_context is None: user_context = {} return ( await PasswordlessRecipe.get_instance().recipe_implementation.get_user_by_email( email=email, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) ) async def get_user_by_phone_number( - phone_number: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, phone_number: str, user_context: Union[None, Dict[str, Any]] = None ) -> Union[User, None]: if user_context is None: user_context = {} return await PasswordlessRecipe.get_instance().recipe_implementation.get_user_by_phone_number( phone_number=phone_number, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -187,9 +181,9 @@ async def delete_phone_number_for_user( async def revoke_all_codes( + tenant_id: str, email: Union[str, None] = None, phone_number: Union[str, None] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> RevokeAllCodesOkResult: if user_context is None: @@ -198,84 +192,76 @@ async def revoke_all_codes( await PasswordlessRecipe.get_instance().recipe_implementation.revoke_all_codes( email=email, phone_number=phone_number, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) ) async def revoke_code( - code_id: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, code_id: str, user_context: Union[None, Dict[str, Any]] = None ) -> RevokeCodeOkResult: if user_context is None: user_context = {} return await PasswordlessRecipe.get_instance().recipe_implementation.revoke_code( + tenant_id=tenant_id, code_id=code_id, - tenant_id=tenant_id or DEFAULT_TENANT_ID, user_context=user_context, ) async def list_codes_by_email( - email: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[DeviceType]: if user_context is None: user_context = {} return await PasswordlessRecipe.get_instance().recipe_implementation.list_codes_by_email( - email=email, tenant_id=tenant_id or DEFAULT_TENANT_ID, user_context=user_context + email=email, tenant_id=tenant_id, user_context=user_context ) async def list_codes_by_phone_number( - phone_number: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, phone_number: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[DeviceType]: if user_context is None: user_context = {} return await PasswordlessRecipe.get_instance().recipe_implementation.list_codes_by_phone_number( phone_number=phone_number, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) async def list_codes_by_device_id( - device_id: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, device_id: str, user_context: Union[None, Dict[str, Any]] = None ) -> Union[DeviceType, None]: if user_context is None: user_context = {} return await PasswordlessRecipe.get_instance().recipe_implementation.list_codes_by_device_id( device_id=device_id, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) async def list_codes_by_pre_auth_session_id( + tenant_id: str, pre_auth_session_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[DeviceType, None]: if user_context is None: user_context = {} return await PasswordlessRecipe.get_instance().recipe_implementation.list_codes_by_pre_auth_session_id( pre_auth_session_id=pre_auth_session_id, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) async def create_magic_link( + tenant_id: str, email: Union[str, None], phone_number: Union[str, None], - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> str: if user_context is None: @@ -283,15 +269,15 @@ async def create_magic_link( return await PasswordlessRecipe.get_instance().create_magic_link( email=email, phone_number=phone_number, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) async def signinup( + tenant_id: str, email: Union[str, None], phone_number: Union[str, None], - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> ConsumeCodeOkResult: if user_context is None: @@ -299,7 +285,7 @@ async def signinup( return await PasswordlessRecipe.get_instance().signinup( email=email, phone_number=phone_number, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -310,8 +296,6 @@ async def send_email( ): if user_context is None: user_context = {} - if input_.tenant_id is None: - input_.tenant_id = DEFAULT_TENANT_ID return await PasswordlessRecipe.get_instance().email_delivery.ingredient_interface_impl.send_email( input_, user_context @@ -324,8 +308,6 @@ async def send_sms( ): if user_context is None: user_context = {} - if input_.tenant_id is None: - input_.tenant_id = DEFAULT_TENANT_ID return await PasswordlessRecipe.get_instance().sms_delivery.ingredient_interface_impl.send_sms( input_, user_context diff --git a/supertokens_python/recipe/passwordless/syncio/__init__.py b/supertokens_python/recipe/passwordless/syncio/__init__.py index fc44c828f..7210f8153 100644 --- a/supertokens_python/recipe/passwordless/syncio/__init__.py +++ b/supertokens_python/recipe/passwordless/syncio/__init__.py @@ -11,7 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from typing import Any, Dict, List, Union, Optional +from typing import Any, Dict, List, Union from supertokens_python.async_to_sync_wrapper import sync from supertokens_python.recipe.passwordless import asyncio @@ -42,6 +42,7 @@ def create_code( + tenant_id: str, email: Union[None, str] = None, phone_number: Union[None, str] = None, user_input_code: Union[None, str] = None, @@ -49,6 +50,7 @@ def create_code( ) -> CreateCodeOkResult: return sync( asyncio.create_code( + tenant_id, email=email, phone_number=phone_number, user_input_code=user_input_code, @@ -58,6 +60,7 @@ def create_code( def create_new_code_for_device( + tenant_id: str, device_id: str, user_input_code: Union[str, None] = None, user_context: Union[None, Dict[str, Any]] = None, @@ -68,6 +71,7 @@ def create_new_code_for_device( ]: return sync( asyncio.create_new_code_for_device( + tenant_id, device_id=device_id, user_input_code=user_input_code, user_context=user_context, @@ -76,6 +80,7 @@ def create_new_code_for_device( def consume_code( + tenant_id: str, pre_auth_session_id: str, user_input_code: Union[str, None] = None, device_id: Union[str, None] = None, @@ -89,6 +94,7 @@ def consume_code( ]: return sync( asyncio.consume_code( + tenant_id, pre_auth_session_id=pre_auth_session_id, user_input_code=user_input_code, device_id=device_id, @@ -105,19 +111,21 @@ def get_user_by_id( def get_user_by_email( - email: str, user_context: Union[None, Dict[str, Any]] = None + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> Union[User, None]: - return sync(asyncio.get_user_by_email(email=email, user_context=user_context)) + return sync( + asyncio.get_user_by_email(tenant_id, email=email, user_context=user_context) + ) def get_user_by_phone_number( + tenant_id: str, phone_number: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[User, None]: return sync( asyncio.get_user_by_phone_number( - phone_number=phone_number, tenant_id=tenant_id, user_context=user_context + tenant_id=tenant_id, phone_number=phone_number, user_context=user_context ) ) @@ -160,92 +168,97 @@ def delete_phone_number_for_user( def revoke_all_codes( + tenant_id: str, email: Union[str, None] = None, phone_number: Union[str, None] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> RevokeAllCodesOkResult: return sync( asyncio.revoke_all_codes( - email=email, phone_number=phone_number, user_context=user_context + tenant_id, email=email, phone_number=phone_number, user_context=user_context ) ) def revoke_code( - code_id: str, user_context: Union[None, Dict[str, Any]] = None + tenant_id: str, code_id: str, user_context: Union[None, Dict[str, Any]] = None ) -> RevokeCodeOkResult: - return sync(asyncio.revoke_code(code_id=code_id, user_context=user_context)) + return sync( + asyncio.revoke_code(tenant_id, code_id=code_id, user_context=user_context) + ) def list_codes_by_email( - email: str, user_context: Union[None, Dict[str, Any]] = None + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[DeviceType]: - return sync(asyncio.list_codes_by_email(email=email, user_context=user_context)) + return sync( + asyncio.list_codes_by_email(tenant_id, email=email, user_context=user_context) + ) def list_codes_by_phone_number( - phone_number: str, user_context: Union[None, Dict[str, Any]] = None + tenant_id: str, phone_number: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[DeviceType]: return sync( asyncio.list_codes_by_phone_number( - phone_number=phone_number, user_context=user_context + tenant_id, phone_number=phone_number, user_context=user_context ) ) def list_codes_by_device_id( + tenant_id: str, device_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[DeviceType, None]: return sync( asyncio.list_codes_by_device_id( - device_id=device_id, tenant_id=tenant_id, user_context=user_context + tenant_id=tenant_id, device_id=device_id, user_context=user_context ) ) def list_codes_by_pre_auth_session_id( + tenant_id: str, pre_auth_session_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[DeviceType, None]: return sync( asyncio.list_codes_by_pre_auth_session_id( - pre_auth_session_id=pre_auth_session_id, tenant_id=tenant_id, + pre_auth_session_id=pre_auth_session_id, user_context=user_context, ) ) def create_magic_link( + tenant_id: str, email: Union[str, None], phone_number: Union[str, None], - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> str: return sync( asyncio.create_magic_link( + tenant_id=tenant_id, email=email, phone_number=phone_number, - tenant_id=tenant_id, user_context=user_context, ) ) def signinup( + tenant_id: str, email: Union[str, None], phone_number: Union[str, None], - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> ConsumeCodeOkResult: return sync( asyncio.signinup( + tenant_id=tenant_id, email=email, phone_number=phone_number, - tenant_id=tenant_id, user_context=user_context, ) ) diff --git a/supertokens_python/recipe/passwordless/types.py b/supertokens_python/recipe/passwordless/types.py index 00f63279c..38f7bcb82 100644 --- a/supertokens_python/recipe/passwordless/types.py +++ b/supertokens_python/recipe/passwordless/types.py @@ -77,12 +77,12 @@ def __init__( class CreateAndSendCustomEmailParameters: def __init__( self, + tenant_id: str, code_life_time: int, pre_auth_session_id: str, email: str, user_input_code: Union[str, None] = None, url_with_link_code: Union[str, None] = None, - tenant_id: Union[str, None] = None, ): self.email = email self.code_life_time = code_life_time @@ -98,12 +98,12 @@ def __init__( class CreateAndSendCustomTextMessageParameters: def __init__( self, + tenant_id: str, code_life_time: int, pre_auth_session_id: str, phone_number: str, user_input_code: Union[str, None] = None, url_with_link_code: Union[str, None] = None, - tenant_id: Union[str, None] = None, ): self.code_life_time = code_life_time self.pre_auth_session_id = pre_auth_session_id diff --git a/supertokens_python/recipe/session/asyncio/__init__.py b/supertokens_python/recipe/session/asyncio/__init__.py index ed795da42..8443e8363 100644 --- a/supertokens_python/recipe/session/asyncio/__init__.py +++ b/supertokens_python/recipe/session/asyncio/__init__.py @@ -49,11 +49,11 @@ async def create_new_session( + tenant_id: str, request: Any, user_id: str, access_token_payload: Union[Dict[str, Any], None] = None, session_data_in_database: Union[Dict[str, Any], None] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> SessionContainer: if user_context is None: @@ -76,16 +76,16 @@ async def create_new_session( config, app_info, session_data_in_database, - tenant_id or DEFAULT_TENANT_ID, + tenant_id, ) async def create_new_session_without_request_response( + tenant_id: str, user_id: str, access_token_payload: Union[Dict[str, Any], None] = None, session_data_in_database: Union[Dict[str, Any], None] = None, disable_anti_csrf: bool = False, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> SessionContainer: if user_context is None: @@ -117,7 +117,7 @@ async def create_new_session_without_request_response( final_access_token_payload, session_data_in_database, disable_anti_csrf, - tenant_id or DEFAULT_TENANT_ID, + tenant_id, user_context=user_context, ) diff --git a/supertokens_python/recipe/session/recipe_implementation.py b/supertokens_python/recipe/session/recipe_implementation.py index 2a061e9fe..1feab414a 100644 --- a/supertokens_python/recipe/session/recipe_implementation.py +++ b/supertokens_python/recipe/session/recipe_implementation.py @@ -71,11 +71,11 @@ async def create_new_session( result = await session_functions.create_new_session( self, + tenant_id, user_id, disable_anti_csrf is True, access_token_payload, session_data_in_database, - tenant_id, ) log_debug_message("createNewSession: Finished") diff --git a/supertokens_python/recipe/session/session_functions.py b/supertokens_python/recipe/session/session_functions.py index d3fb1cdca..10cb03833 100644 --- a/supertokens_python/recipe/session/session_functions.py +++ b/supertokens_python/recipe/session/session_functions.py @@ -97,19 +97,16 @@ def __init__( async def create_new_session( recipe_implementation: RecipeImplementation, + tenant_id: str, user_id: str, disable_anti_csrf: bool, access_token_payload: Union[None, Dict[str, Any]], session_data_in_database: Union[None, Dict[str, Any]], - tenant_id: Optional[str], ) -> CreateOrRefreshAPIResponse: if session_data_in_database is None: session_data_in_database = {} if access_token_payload is None: access_token_payload = {} - if tenant_id is None: - tenant_id = DEFAULT_TENANT_ID - enable_anti_csrf = ( disable_anti_csrf is False and recipe_implementation.config.anti_csrf == "VIA_TOKEN" diff --git a/supertokens_python/recipe/session/syncio/__init__.py b/supertokens_python/recipe/session/syncio/__init__.py index dc4e9d140..6c3ecea0f 100644 --- a/supertokens_python/recipe/session/syncio/__init__.py +++ b/supertokens_python/recipe/session/syncio/__init__.py @@ -39,11 +39,11 @@ def create_new_session( + tenant_id: str, request: Any, user_id: str, access_token_payload: Union[Dict[str, Any], None] = None, session_data_in_database: Union[Dict[str, Any], None] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> SessionContainer: from supertokens_python.recipe.session.asyncio import ( @@ -52,22 +52,22 @@ def create_new_session( return sync( async_create_new_session( - request, - user_id, - access_token_payload, - session_data_in_database, - tenant_id, - user_context, + tenant_id=tenant_id, + request=request, + user_id=user_id, + access_token_payload=access_token_payload, + session_data_in_database=session_data_in_database, + user_context=user_context, ) ) def create_new_session_without_request_response( + tenant_id: str, user_id: str, access_token_payload: Union[Dict[str, Any], None] = None, session_data_in_database: Union[Dict[str, Any], None] = None, disable_anti_csrf: bool = False, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> SessionContainer: from supertokens_python.recipe.session.asyncio import ( @@ -76,11 +76,11 @@ def create_new_session_without_request_response( return sync( async_create_new_session_without_request_response( + tenant_id, user_id, access_token_payload, session_data_in_database, disable_anti_csrf, - tenant_id, user_context, ) ) diff --git a/supertokens_python/recipe/thirdparty/api/implementation.py b/supertokens_python/recipe/thirdparty/api/implementation.py index eef9c6ce2..4caec19b0 100644 --- a/supertokens_python/recipe/thirdparty/api/implementation.py +++ b/supertokens_python/recipe/thirdparty/api/implementation.py @@ -115,24 +115,24 @@ async def sign_in_up_post( ev_instance = EmailVerificationRecipe.get_instance_optional() if ev_instance is not None: token_response = await ev_instance.recipe_implementation.create_email_verification_token( + tenant_id=tenant_id, user_id=signinup_response.user.user_id, email=signinup_response.user.email, - tenant_id=tenant_id, user_context=user_context, ) if isinstance(token_response, CreateEmailVerificationTokenOkResult): await ev_instance.recipe_implementation.verify_email_using_token( - token=token_response.token, tenant_id=tenant_id, + token=token_response.token, user_context=user_context, ) user = signinup_response.user session = await create_new_session( - api_options.request, - user.user_id, tenant_id=tenant_id, + request=api_options.request, + user_id=user.user_id, user_context=user_context, ) diff --git a/supertokens_python/recipe/thirdparty/asyncio/__init__.py b/supertokens_python/recipe/thirdparty/asyncio/__init__.py index dfc1e84d6..a216461dc 100644 --- a/supertokens_python/recipe/thirdparty/asyncio/__init__.py +++ b/supertokens_python/recipe/thirdparty/asyncio/__init__.py @@ -32,9 +32,7 @@ async def get_user_by_id( async def get_users_by_email( - email: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[User]: if user_context is None: user_context = {} @@ -46,9 +44,9 @@ async def get_users_by_email( async def get_user_by_third_party_info( + tenant_id: str, third_party_id: str, third_party_user_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -56,16 +54,16 @@ async def get_user_by_third_party_info( return await ThirdPartyRecipe.get_instance().recipe_implementation.get_user_by_thirdparty_info( third_party_id, third_party_user_id, - tenant_id or DEFAULT_TENANT_ID, + tenant_id, user_context, ) async def manually_create_or_update_user( + tenant_id: str, third_party_id: str, third_party_user_id: str, email: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -74,19 +72,19 @@ async def manually_create_or_update_user( third_party_id, third_party_user_id, email, - tenant_id or DEFAULT_TENANT_ID, + tenant_id, user_context, ) async def get_provider( + tenant_id: str, third_party_id: str, client_type: Optional[str] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: user_context = {} return await ThirdPartyRecipe.get_instance().recipe_implementation.get_provider( - third_party_id, client_type, tenant_id or DEFAULT_TENANT_ID, user_context + third_party_id, client_type, tenant_id, user_context ) diff --git a/supertokens_python/recipe/thirdparty/recipe_implementation.py b/supertokens_python/recipe/thirdparty/recipe_implementation.py index 8d6b6ef42..f7f978667 100644 --- a/supertokens_python/recipe/thirdparty/recipe_implementation.py +++ b/supertokens_python/recipe/thirdparty/recipe_implementation.py @@ -180,7 +180,7 @@ async def get_provider( self, third_party_id: str, client_type: Optional[str], - tenant_id: Optional[str], + tenant_id: str, user_context: Dict[str, Any], ): mt_recipe = MultitenancyRecipe.get_instance() diff --git a/supertokens_python/recipe/thirdparty/syncio/__init__.py b/supertokens_python/recipe/thirdparty/syncio/__init__.py index a342a336e..218c6862e 100644 --- a/supertokens_python/recipe/thirdparty/syncio/__init__.py +++ b/supertokens_python/recipe/thirdparty/syncio/__init__.py @@ -27,19 +27,19 @@ def get_user_by_id( def get_users_by_email( + tenant_id: str, email: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> List[User]: from supertokens_python.recipe.thirdparty.asyncio import get_users_by_email - return sync(get_users_by_email(email, tenant_id, user_context)) + return sync(get_users_by_email(tenant_id, email, user_context)) def get_user_by_third_party_info( + tenant_id: str, third_party_id: str, third_party_user_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.thirdparty.asyncio import ( @@ -48,16 +48,16 @@ def get_user_by_third_party_info( return sync( get_user_by_third_party_info( - third_party_id, third_party_user_id, tenant_id, user_context + tenant_id, third_party_id, third_party_user_id, user_context ) ) def manually_create_or_update_user( + tenant_id: str, third_party_id: str, third_party_user_id: str, email: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.thirdparty.asyncio import ( @@ -66,17 +66,17 @@ def manually_create_or_update_user( return sync( manually_create_or_update_user( - third_party_id, third_party_user_id, email, tenant_id, user_context + tenant_id, third_party_id, third_party_user_id, email, user_context ) ) def get_provider( + tenant_id: str, third_party_id: str, client_type: Optional[str] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.thirdparty.asyncio import get_provider - return sync(get_provider(third_party_id, client_type, tenant_id, user_context)) + return sync(get_provider(tenant_id, third_party_id, client_type, user_context)) diff --git a/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py b/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py index 34b7d3677..438a2fd16 100644 --- a/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py +++ b/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py @@ -48,9 +48,9 @@ async def get_user_by_id( async def get_user_by_third_party_info( + tenant_id: str, third_party_id: str, third_party_user_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -64,12 +64,12 @@ async def get_user_by_third_party_info( async def thirdparty_sign_in_up( + tenant_id: str, third_party_id: str, third_party_user_id: str, email: str, oauth_tokens: Dict[str, Any], raw_user_info_from_provider: RawUserInfoFromProvider, - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ): if user_context is None: @@ -87,10 +87,10 @@ async def thirdparty_sign_in_up( async def thirdparty_manually_create_or_update_user( + tenant_id: str, third_party_id: str, third_party_user_id: str, email: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -105,9 +105,9 @@ async def thirdparty_manually_create_or_update_user( async def thirdparty_get_provider( + tenant_id: str, third_party_id: str, client_type: Optional[str] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -118,9 +118,7 @@ async def thirdparty_get_provider( async def create_reset_password_token( - user_id: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, user_id: str, user_context: Union[None, Dict[str, Any]] = None ): if user_context is None: user_context = {} @@ -130,9 +128,9 @@ async def create_reset_password_token( async def reset_password_using_token( + tenant_id: str, token: str, new_password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -143,9 +141,9 @@ async def reset_password_using_token( async def emailpassword_sign_in( + tenant_id: str, email: str, password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -156,9 +154,9 @@ async def emailpassword_sign_in( async def emailpassword_sign_up( + tenant_id: str, email: str, password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -189,9 +187,7 @@ async def update_email_or_password( async def get_users_by_email( - email: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[User]: if user_context is None: user_context = {} @@ -215,11 +211,9 @@ async def send_email( async def create_reset_password_link( - user_id: str, - tenant_id: Optional[str] = None, - user_context: Optional[Dict[str, Any]] = None, + tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None ): - token = await create_reset_password_token(user_id, tenant_id, user_context) + token = await create_reset_password_token(tenant_id, user_id, user_context) if isinstance(token, CreateResetPasswordWrongUserIdError): return CreateResetPasswordLinkUknownUserIdError() @@ -239,11 +233,11 @@ async def create_reset_password_link( async def send_reset_password_email( + tenant_id: str, user_id: str, - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ): - link = await create_reset_password_link(user_id, tenant_id, user_context) + link = await create_reset_password_link(tenant_id, user_id, user_context) if isinstance(link, CreateResetPasswordLinkUknownUserIdError): return CreateResetPasswordEmailUnknownUserIdError() diff --git a/supertokens_python/recipe/thirdpartyemailpassword/interfaces.py b/supertokens_python/recipe/thirdpartyemailpassword/interfaces.py index abfa213a9..2aa4bc2ac 100644 --- a/supertokens_python/recipe/thirdpartyemailpassword/interfaces.py +++ b/supertokens_python/recipe/thirdpartyemailpassword/interfaces.py @@ -147,7 +147,7 @@ async def thirdparty_get_provider( self, third_party_id: str, client_type: Optional[str], - tenant_id: Optional[str], + tenant_id: str, user_context: Dict[str, Any], ) -> ThirdPartyInterfaces.GetProviderOkResult: pass diff --git a/supertokens_python/recipe/thirdpartyemailpassword/recipeimplementation/implementation.py b/supertokens_python/recipe/thirdpartyemailpassword/recipeimplementation/implementation.py index ad563d817..95472eaab 100644 --- a/supertokens_python/recipe/thirdpartyemailpassword/recipeimplementation/implementation.py +++ b/supertokens_python/recipe/thirdpartyemailpassword/recipeimplementation/implementation.py @@ -274,7 +274,7 @@ async def thirdparty_get_provider( self, third_party_id: str, client_type: Optional[str], - tenant_id: Optional[str], + tenant_id: str, user_context: Dict[str, Any], ) -> GetProviderOkResult: if self.tp_get_provider is None: diff --git a/supertokens_python/recipe/thirdpartyemailpassword/recipeimplementation/third_party_recipe_implementation.py b/supertokens_python/recipe/thirdpartyemailpassword/recipeimplementation/third_party_recipe_implementation.py index ae4639fe2..581c45b19 100644 --- a/supertokens_python/recipe/thirdpartyemailpassword/recipeimplementation/third_party_recipe_implementation.py +++ b/supertokens_python/recipe/thirdpartyemailpassword/recipeimplementation/third_party_recipe_implementation.py @@ -162,7 +162,7 @@ async def get_provider( self, third_party_id: str, client_type: Optional[str], - tenant_id: Optional[str], + tenant_id: str, user_context: Dict[str, Any], ) -> GetProviderOkResult: return await self.recipe_implementation.thirdparty_get_provider( diff --git a/supertokens_python/recipe/thirdpartyemailpassword/syncio/__init__.py b/supertokens_python/recipe/thirdpartyemailpassword/syncio/__init__.py index 191797119..1f061e771 100644 --- a/supertokens_python/recipe/thirdpartyemailpassword/syncio/__init__.py +++ b/supertokens_python/recipe/thirdpartyemailpassword/syncio/__init__.py @@ -33,9 +33,9 @@ def get_user_by_id( def get_user_by_third_party_info( + tenant_id: str, third_party_id: str, third_party_user_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( @@ -44,18 +44,18 @@ def get_user_by_third_party_info( return sync( get_user_by_third_party_info( - third_party_id, third_party_user_id, tenant_id, user_context + tenant_id, third_party_id, third_party_user_id, user_context ) ) def thirdparty_sign_in_up( + tenant_id: str, third_party_id: str, third_party_user_id: str, email: str, oauth_tokens: Dict[str, Any], raw_user_info_from_provider: RawUserInfoFromProvider, - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ): from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( @@ -64,22 +64,22 @@ def thirdparty_sign_in_up( return sync( thirdparty_sign_in_up( + tenant_id, third_party_id, third_party_user_id, email, oauth_tokens, raw_user_info_from_provider, - tenant_id, user_context, ) ) def thirdparty_manually_create_or_update_user( + tenant_id: str, third_party_id: str, third_party_user_id: str, email: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( @@ -88,15 +88,15 @@ def thirdparty_manually_create_or_update_user( return sync( thirdparty_manually_create_or_update_user( - third_party_id, third_party_user_id, email, tenant_id, user_context + tenant_id, third_party_id, third_party_user_id, email, user_context ) ) def thirdparty_get_provider( + tenant_id: str, third_party_id: str, client_type: Optional[str] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( @@ -104,26 +104,24 @@ def thirdparty_get_provider( ) return sync( - thirdparty_get_provider(third_party_id, client_type, tenant_id, user_context) + thirdparty_get_provider(tenant_id, third_party_id, client_type, user_context) ) def create_reset_password_token( - user_id: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, user_id: str, user_context: Union[None, Dict[str, Any]] = None ): from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( create_reset_password_token, ) - return sync(create_reset_password_token(user_id, tenant_id, user_context)) + return sync(create_reset_password_token(tenant_id, user_id, user_context)) def reset_password_using_token( + tenant_id: str, token: str, new_password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( @@ -131,34 +129,34 @@ def reset_password_using_token( ) return sync( - reset_password_using_token(token, new_password, tenant_id, user_context) + reset_password_using_token(tenant_id, token, new_password, user_context) ) def emailpassword_sign_in( + tenant_id: str, email: str, password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[EmailPasswordSignInOkResult, EmailPasswordSignInWrongCredentialsError]: from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( emailpassword_sign_in, ) - return sync(emailpassword_sign_in(email, password, tenant_id, user_context)) + return sync(emailpassword_sign_in(tenant_id, email, password, user_context)) def emailpassword_sign_up( + tenant_id: str, email: str, password: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( emailpassword_sign_up, ) - return sync(emailpassword_sign_up(email, password, tenant_id, user_context)) + return sync(emailpassword_sign_up(tenant_id, email, password, user_context)) def update_email_or_password( @@ -186,15 +184,13 @@ def update_email_or_password( def get_users_by_email( - email: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[User]: from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( get_users_by_email, ) - return sync(get_users_by_email(email, tenant_id, user_context)) + return sync(get_users_by_email(tenant_id, email, user_context)) def send_email( @@ -207,24 +203,22 @@ def send_email( def create_reset_password_link( - user_id: str, - tenant_id: Optional[str] = None, - user_context: Optional[Dict[str, Any]] = None, + tenant_id: str, user_id: str, user_context: Optional[Dict[str, Any]] = None ): from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( create_reset_password_link, ) - return sync(create_reset_password_link(user_id, tenant_id, user_context)) + return sync(create_reset_password_link(tenant_id, user_id, user_context)) def send_reset_password_email( + tenant_id: str, user_id: str, - tenant_id: Optional[str] = None, user_context: Optional[Dict[str, Any]] = None, ): from supertokens_python.recipe.thirdpartyemailpassword.asyncio import ( send_reset_password_email, ) - return sync(send_reset_password_email(user_id, tenant_id, user_context)) + return sync(send_reset_password_email(tenant_id, user_id, user_context)) diff --git a/supertokens_python/recipe/thirdpartypasswordless/asyncio/__init__.py b/supertokens_python/recipe/thirdpartypasswordless/asyncio/__init__.py index f48def8d1..7bb72666a 100644 --- a/supertokens_python/recipe/thirdpartypasswordless/asyncio/__init__.py +++ b/supertokens_python/recipe/thirdpartypasswordless/asyncio/__init__.py @@ -37,9 +37,9 @@ async def get_user_by_id( async def get_user_by_third_party_info( + tenant_id: str, third_party_id: str, third_party_user_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -53,10 +53,10 @@ async def get_user_by_third_party_info( async def thirdparty_manually_create_or_update_user( + tenant_id: str, third_party_id: str, third_party_user_id: str, email: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -71,9 +71,9 @@ async def thirdparty_manually_create_or_update_user( async def thirdparty_get_provider( + tenant_id: str, third_party_id: str, client_type: Optional[str] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): if user_context is None: @@ -84,9 +84,7 @@ async def thirdparty_get_provider( async def get_users_by_email( - email: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[User]: if user_context is None: user_context = {} @@ -96,10 +94,10 @@ async def get_users_by_email( async def create_code( + tenant_id: str, email: Union[None, str] = None, phone_number: Union[None, str] = None, user_input_code: Union[None, str] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> interfaces.CreateCodeOkResult: if user_context is None: @@ -114,9 +112,9 @@ async def create_code( async def create_new_code_for_device( + tenant_id: str, device_id: str, user_input_code: Union[str, None] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[ interfaces.CreateNewCodeForDeviceOkResult, @@ -134,11 +132,11 @@ async def create_new_code_for_device( async def consume_code( + tenant_id: str, pre_auth_session_id: str, user_input_code: Union[str, None] = None, device_id: Union[str, None] = None, link_code: Union[str, None] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[ interfaces.ConsumeCodeOkResult, @@ -159,9 +157,7 @@ async def consume_code( async def get_user_by_phone_number( - phone_number: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, phone_number: str, user_context: Union[None, Dict[str, Any]] = None ) -> Union[User, None]: if user_context is None: user_context = {} @@ -214,9 +210,9 @@ async def delete_phone_number_for_user( async def revoke_all_codes( + tenant_id: str, email: Union[str, None] = None, phone_number: Union[str, None] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> interfaces.RevokeAllCodesOkResult: if user_context is None: @@ -230,9 +226,7 @@ async def revoke_all_codes( async def revoke_code( - code_id: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, code_id: str, user_context: Union[None, Dict[str, Any]] = None ) -> interfaces.RevokeCodeOkResult: if user_context is None: user_context = {} @@ -244,9 +238,7 @@ async def revoke_code( async def list_codes_by_email( - email: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[interfaces.DeviceType]: if user_context is None: user_context = {} @@ -256,9 +248,7 @@ async def list_codes_by_email( async def list_codes_by_phone_number( - phone_number: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, phone_number: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[interfaces.DeviceType]: if user_context is None: user_context = {} @@ -270,9 +260,7 @@ async def list_codes_by_phone_number( async def list_codes_by_device_id( - device_id: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, device_id: str, user_context: Union[None, Dict[str, Any]] = None ) -> Union[interfaces.DeviceType, None]: if user_context is None: user_context = {} @@ -284,8 +272,8 @@ async def list_codes_by_device_id( async def list_codes_by_pre_auth_session_id( + tenant_id: str, pre_auth_session_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[interfaces.DeviceType, None]: if user_context is None: @@ -298,34 +286,34 @@ async def list_codes_by_pre_auth_session_id( async def create_magic_link( + tenant_id: str, email: Union[str, None], phone_number: Union[str, None], - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> str: if user_context is None: user_context = {} return await ThirdPartyPasswordlessRecipe.get_instance().passwordless_recipe.create_magic_link( + tenant_id=tenant_id or DEFAULT_TENANT_ID, email=email, phone_number=phone_number, - tenant_id=tenant_id or DEFAULT_TENANT_ID, user_context=user_context, ) async def passwordlessSigninup( + tenant_id: str, email: Union[str, None], phone_number: Union[str, None], - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> interfaces.ConsumeCodeOkResult: if user_context is None: user_context = {} result = ( await ThirdPartyPasswordlessRecipe.get_instance().passwordless_recipe.signinup( + tenant_id=tenant_id or DEFAULT_TENANT_ID, email=email, phone_number=phone_number, - tenant_id=tenant_id or DEFAULT_TENANT_ID, user_context=user_context, ) ) diff --git a/supertokens_python/recipe/thirdpartypasswordless/syncio/__init__.py b/supertokens_python/recipe/thirdpartypasswordless/syncio/__init__.py index 4273cf61c..e04572e8a 100644 --- a/supertokens_python/recipe/thirdpartypasswordless/syncio/__init__.py +++ b/supertokens_python/recipe/thirdpartypasswordless/syncio/__init__.py @@ -33,81 +33,79 @@ def get_user_by_id( def get_user_by_third_party_info( + tenant_id: str, third_party_id: str, third_party_user_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from ..asyncio import get_user_by_third_party_info return sync( get_user_by_third_party_info( - third_party_id, third_party_user_id, tenant_id, user_context + tenant_id, third_party_id, third_party_user_id, user_context ) ) def thirdparty_manually_create_or_update_user( + tenant_id: str, third_party_id: str, third_party_user_id: str, email: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from ..asyncio import thirdparty_manually_create_or_update_user return sync( thirdparty_manually_create_or_update_user( - third_party_id, third_party_user_id, email, tenant_id, user_context + tenant_id, third_party_id, third_party_user_id, email, user_context ) ) def thirdparty_get_provider( + tenant_id: str, third_party_id: str, client_type: Optional[str] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ): from ..asyncio import thirdparty_get_provider return sync( - thirdparty_get_provider(third_party_id, client_type, tenant_id, user_context) + thirdparty_get_provider(tenant_id, third_party_id, client_type, user_context) ) def get_users_by_email( - email: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[User]: from ..asyncio import get_users_by_email - return sync(get_users_by_email(email, tenant_id, user_context)) + return sync(get_users_by_email(tenant_id, email, user_context)) def create_code( + tenant_id: str, email: Union[None, str] = None, phone_number: Union[None, str] = None, user_input_code: Union[None, str] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> interfaces.CreateCodeOkResult: return sync( asyncio.create_code( + tenant_id=tenant_id, email=email, phone_number=phone_number, user_input_code=user_input_code, - tenant_id=tenant_id, user_context=user_context, ) ) def create_new_code_for_device( + tenant_id: str, device_id: str, user_input_code: Union[str, None] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[ interfaces.CreateNewCodeForDeviceOkResult, @@ -116,20 +114,20 @@ def create_new_code_for_device( ]: return sync( asyncio.create_new_code_for_device( + tenant_id=tenant_id, device_id=device_id, user_input_code=user_input_code, - tenant_id=tenant_id, user_context=user_context, ) ) def consume_code( + tenant_id: str, pre_auth_session_id: str, user_input_code: Union[str, None] = None, device_id: Union[str, None] = None, link_code: Union[str, None] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[ interfaces.ConsumeCodeOkResult, @@ -139,24 +137,22 @@ def consume_code( ]: return sync( asyncio.consume_code( + tenant_id=tenant_id, pre_auth_session_id=pre_auth_session_id, user_input_code=user_input_code, device_id=device_id, link_code=link_code, - tenant_id=tenant_id, user_context=user_context, ) ) def get_user_by_phone_number( - phone_number: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, phone_number: str, user_context: Union[None, Dict[str, Any]] = None ) -> Union[User, None]: return sync( asyncio.get_user_by_phone_number( - phone_number=phone_number, tenant_id=tenant_id, user_context=user_context + tenant_id=tenant_id, phone_number=phone_number, user_context=user_context ) ) @@ -201,110 +197,102 @@ def delete_phone_number_for_user( def revoke_all_codes( + tenant_id: str, email: Union[str, None] = None, phone_number: Union[str, None] = None, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> interfaces.RevokeAllCodesOkResult: return sync( asyncio.revoke_all_codes( + tenant_id=tenant_id, email=email, phone_number=phone_number, - tenant_id=tenant_id, user_context=user_context, ) ) def revoke_code( - code_id: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, code_id: str, user_context: Union[None, Dict[str, Any]] = None ) -> interfaces.RevokeCodeOkResult: return sync( asyncio.revoke_code( - code_id=code_id, tenant_id=tenant_id, user_context=user_context + tenant_id=tenant_id, code_id=code_id, user_context=user_context ) ) def list_codes_by_email( - email: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[interfaces.DeviceType]: return sync( asyncio.list_codes_by_email( - email=email, tenant_id=tenant_id, user_context=user_context + tenant_id=tenant_id, email=email, user_context=user_context ) ) def list_codes_by_phone_number( - phone_number: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, phone_number: str, user_context: Union[None, Dict[str, Any]] = None ) -> List[interfaces.DeviceType]: return sync( asyncio.list_codes_by_phone_number( - phone_number=phone_number, tenant_id=tenant_id, user_context=user_context + tenant_id=tenant_id, phone_number=phone_number, user_context=user_context ) ) def list_codes_by_device_id( - device_id: str, - tenant_id: Optional[str] = None, - user_context: Union[None, Dict[str, Any]] = None, + tenant_id: str, device_id: str, user_context: Union[None, Dict[str, Any]] = None ) -> Union[interfaces.DeviceType, None]: return sync( asyncio.list_codes_by_device_id( - device_id=device_id, tenant_id=tenant_id, user_context=user_context + tenant_id=tenant_id, device_id=device_id, user_context=user_context ) ) def list_codes_by_pre_auth_session_id( + tenant_id: str, pre_auth_session_id: str, - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> Union[interfaces.DeviceType, None]: return sync( asyncio.list_codes_by_pre_auth_session_id( - pre_auth_session_id=pre_auth_session_id, tenant_id=tenant_id, + pre_auth_session_id=pre_auth_session_id, user_context=user_context, ) ) def create_magic_link( + tenant_id: str, email: Union[str, None], phone_number: Union[str, None], - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> str: return sync( asyncio.create_magic_link( + tenant_id=tenant_id, email=email, phone_number=phone_number, - tenant_id=tenant_id, user_context=user_context, ) ) def passwordlessSigninup( + tenant_id: str, email: Union[str, None], phone_number: Union[str, None], - tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None, ) -> interfaces.ConsumeCodeOkResult: return sync( asyncio.passwordlessSigninup( + tenant_id=tenant_id, email=email, phone_number=phone_number, - tenant_id=tenant_id, user_context=user_context, ) ) diff --git a/supertokens_python/recipe/userroles/asyncio/__init__.py b/supertokens_python/recipe/userroles/asyncio/__init__.py index 4a296f035..833d09dde 100644 --- a/supertokens_python/recipe/userroles/asyncio/__init__.py +++ b/supertokens_python/recipe/userroles/asyncio/__init__.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Union, Optional +from typing import Any, Dict, List, Union from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID from supertokens_python.recipe.userroles.interfaces import ( @@ -18,35 +18,33 @@ async def add_role_to_user( + tenant_id: str, user_id: str, role: str, - tenant_id: Optional[str] = None, user_context: Union[Dict[str, Any], None] = None, ) -> Union[AddRoleToUserOkResult, UnknownRoleError]: if user_context is None: user_context = {} return await UserRolesRecipe.get_instance().recipe_implementation.add_role_to_user( - user_id, role, tenant_id or DEFAULT_TENANT_ID, user_context + role, tenant_id or DEFAULT_TENANT_ID, user_id, user_context ) async def remove_user_role( + tenant_id: str, user_id: str, role: str, - tenant_id: Optional[str] = None, user_context: Union[Dict[str, Any], None] = None, ) -> Union[RemoveUserRoleOkResult, UnknownRoleError]: if user_context is None: user_context = {} return await UserRolesRecipe.get_instance().recipe_implementation.remove_user_role( - user_id, role, tenant_id or DEFAULT_TENANT_ID, user_context + role, tenant_id or DEFAULT_TENANT_ID, user_id, user_context ) async def get_roles_for_user( - user_id: str, - tenant_id: Optional[str] = None, - user_context: Union[Dict[str, Any], None] = None, + tenant_id: str, user_id: str, user_context: Union[Dict[str, Any], None] = None ) -> GetRolesForUserOkResult: if user_context is None: user_context = {} @@ -58,9 +56,7 @@ async def get_roles_for_user( async def get_users_that_have_role( - role: str, - tenant_id: Optional[str] = None, - user_context: Union[Dict[str, Any], None] = None, + tenant_id: str, role: str, user_context: Union[Dict[str, Any], None] = None ) -> Union[GetUsersThatHaveRoleOkResult, UnknownRoleError]: if user_context is None: user_context = {} diff --git a/supertokens_python/recipe/userroles/syncio/__init__.py b/supertokens_python/recipe/userroles/syncio/__init__.py index 9843034fb..8cb30ad82 100644 --- a/supertokens_python/recipe/userroles/syncio/__init__.py +++ b/supertokens_python/recipe/userroles/syncio/__init__.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from typing import Any, Dict, List, Union, Optional +from typing import Any, Dict, List, Union from supertokens_python.async_to_sync_wrapper import sync from supertokens_python.recipe.userroles.interfaces import ( @@ -31,45 +31,41 @@ def add_role_to_user( + tenant_id: str, user_id: str, role: str, - tenant_id: Optional[str] = None, user_context: Union[Dict[str, Any], None] = None, ) -> Union[AddRoleToUserOkResult, UnknownRoleError]: from supertokens_python.recipe.userroles.asyncio import add_role_to_user - return sync(add_role_to_user(user_id, role, tenant_id, user_context)) + return sync(add_role_to_user(tenant_id, user_id, role, user_context)) def remove_user_role( + tenant_id: str, user_id: str, role: str, - tenant_id: Optional[str] = None, user_context: Union[Dict[str, Any], None] = None, ) -> Union[RemoveUserRoleOkResult, UnknownRoleError]: from supertokens_python.recipe.userroles.asyncio import remove_user_role - return sync(remove_user_role(user_id, role, tenant_id, user_context)) + return sync(remove_user_role(tenant_id, user_id, role, user_context)) def get_roles_for_user( - user_id: str, - tenant_id: Optional[str] = None, - user_context: Union[Dict[str, Any], None] = None, + tenant_id: str, user_id: str, user_context: Union[Dict[str, Any], None] = None ) -> GetRolesForUserOkResult: from supertokens_python.recipe.userroles.asyncio import get_roles_for_user - return sync(get_roles_for_user(user_id, tenant_id, user_context)) + return sync(get_roles_for_user(tenant_id, user_id, user_context)) def get_users_that_have_role( - role: str, - tenant_id: Optional[str] = None, - user_context: Union[Dict[str, Any], None] = None, + tenant_id: str, role: str, user_context: Union[Dict[str, Any], None] = None ) -> Union[GetUsersThatHaveRoleOkResult, UnknownRoleError]: from supertokens_python.recipe.userroles.asyncio import get_users_that_have_role - return sync(get_users_that_have_role(role, tenant_id, user_context)) + return sync(get_users_that_have_role(tenant_id, role, user_context)) def create_new_role_or_add_permissions( diff --git a/supertokens_python/supertokens.py b/supertokens_python/supertokens.py index 214683250..1a8c3afcc 100644 --- a/supertokens_python/supertokens.py +++ b/supertokens_python/supertokens.py @@ -260,15 +260,13 @@ async def get_user_count( # pylint: disable=no-self-use include_recipe_ids: Union[None, List[str]], tenant_id: Optional[str] = None, ) -> int: - from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID - querier = Querier.get_instance(None) include_recipe_ids_str = None if include_recipe_ids is not None: include_recipe_ids_str = ",".join(include_recipe_ids) response = await querier.send_get_request( - NormalisedURLPath(f"/{tenant_id or DEFAULT_TENANT_ID}{USER_COUNT}"), + NormalisedURLPath(f"/{tenant_id}{USER_COUNT}"), { "includeRecipeIds": include_recipe_ids_str, "includeAllTenants": tenant_id is None, @@ -292,12 +290,12 @@ async def delete_user(self, user_id: str) -> None: # pylint: disable=no-self-us async def get_users( # pylint: disable=no-self-use self, + tenant_id: str, time_joined_order: Literal["ASC", "DESC"], limit: Union[int, None], pagination_token: Union[str, None], include_recipe_ids: Union[None, List[str]], query: Union[Dict[str, str], None] = None, - tenant_id: Optional[str] = None, ) -> UsersResponse: from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID diff --git a/supertokens_python/syncio/__init__.py b/supertokens_python/syncio/__init__.py index 24a8ea476..874a8a35c 100644 --- a/supertokens_python/syncio/__init__.py +++ b/supertokens_python/syncio/__init__.py @@ -36,7 +36,7 @@ def get_users_oldest_first( ) -> UsersResponse: return sync( Supertokens.get_instance().get_users( - "ASC", limit, pagination_token, include_recipe_ids, query + "public", "ASC", limit, pagination_token, include_recipe_ids, query ) ) @@ -49,7 +49,7 @@ def get_users_newest_first( ) -> UsersResponse: return sync( Supertokens.get_instance().get_users( - "DESC", limit, pagination_token, include_recipe_ids, query + "public", "DESC", limit, pagination_token, include_recipe_ids, query ) ) diff --git a/tests/Django/test_django.py b/tests/Django/test_django.py index 372e72269..cb71fd8ea 100644 --- a/tests/Django/test_django.py +++ b/tests/Django/test_django.py @@ -75,7 +75,7 @@ def get_cookies(response: HttpResponse) -> Dict[str, Any]: async def create_new_session_view(request: HttpRequest): - await create_new_session(request, "user_id") + await create_new_session("public", request, "user_id") return JsonResponse({"foo": "bar"}) diff --git a/tests/Fastapi/test_fastapi.py b/tests/Fastapi/test_fastapi.py index fc4cebbcb..d56287afe 100644 --- a/tests/Fastapi/test_fastapi.py +++ b/tests/Fastapi/test_fastapi.py @@ -91,7 +91,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session(request, user_id, {}, {}) + await create_new_session("public", request, user_id, {}, {}) return {"userId": user_id} @app.post("/refresh") @@ -135,12 +135,12 @@ async def custom_logout(request: Request): # type: ignore @app.post("/create") async def _create(request: Request): # type: ignore - await create_new_session(request, "userId", {}, {}) + await create_new_session("public", request, "userId", {}, {}) return "" @app.post("/create-throw") async def _create_throw(request: Request): # type: ignore - await create_new_session(request, "userId", {}, {}) + await create_new_session("public", request, "userId", {}, {}) raise UnauthorisedError("unauthorised") return TestClient(app) diff --git a/tests/Flask/test_flask.py b/tests/Flask/test_flask.py index 3770d7d60..75c08a4f3 100644 --- a/tests/Flask/test_flask.py +++ b/tests/Flask/test_flask.py @@ -191,7 +191,7 @@ def t(): # type: ignore @app.route("/login") # type: ignore def login(): # type: ignore user_id = "userId" - create_new_session(request, user_id, {}, {}) + create_new_session("public", request, user_id, {}, {}) return jsonify({"userId": user_id, "session": "ssss"}) @@ -748,7 +748,7 @@ def test_api(): # type: ignore @app.route("/login") # type: ignore def login(): # type: ignore user_id = "userId" - s = create_new_session(request, user_id, {}, {}) + s = create_new_session("public", request, user_id, {}, {}) return jsonify({"user": s.get_user_id()}) @app.route("/ping") # type: ignore diff --git a/tests/auth-react/django3x/polls/views.py b/tests/auth-react/django3x/polls/views.py index 1d48d089a..db45b921a 100644 --- a/tests/auth-react/django3x/polls/views.py +++ b/tests/auth-react/django3x/polls/views.py @@ -77,7 +77,7 @@ async def set_role_api(request: HttpRequest): session_: SessionContainer = request.supertokens # type: ignore body = json.loads(request.body) await create_new_role_or_add_permissions(body["role"], body["permissions"]) - await add_role_to_user(session_.get_user_id(), body["role"]) + await add_role_to_user("public", session_.get_user_id(), body["role"]) await session_.fetch_and_set_claim(UserRoleClaim) await session_.fetch_and_set_claim(PermissionClaim) return JsonResponse({"status": "OK"}) @@ -120,7 +120,7 @@ def sync_set_role_api(request: HttpRequest): session_: SessionContainer = request.supertokens # type: ignore body = json.loads(request.body) sync_create_new_role_or_add_permissions(body["role"], body["permissions"]) - sync_add_role_to_user(session_.get_user_id(), body["role"]) + sync_add_role_to_user("public", session_.get_user_id(), body["role"]) session_.sync_fetch_and_set_claim(UserRoleClaim) session_.sync_fetch_and_set_claim(PermissionClaim) return JsonResponse({"status": "OK"}) diff --git a/tests/auth-react/fastapi-server/app.py b/tests/auth-react/fastapi-server/app.py index 33ba03371..3094dfe23 100644 --- a/tests/auth-react/fastapi-server/app.py +++ b/tests/auth-react/fastapi-server/app.py @@ -1104,7 +1104,7 @@ async def set_role_api( ): body = await request.json() await create_new_role_or_add_permissions(body["role"], body["permissions"]) - await add_role_to_user(session_.get_user_id(), body["role"]) + await add_role_to_user("public", session_.get_user_id(), body["role"]) await session_.fetch_and_set_claim(UserRoleClaim) await session_.fetch_and_set_claim(PermissionClaim) return JSONResponse({"status": "OK"}) diff --git a/tests/auth-react/flask-server/app.py b/tests/auth-react/flask-server/app.py index 04a2430a0..2e5b3c979 100644 --- a/tests/auth-react/flask-server/app.py +++ b/tests/auth-react/flask-server/app.py @@ -1119,7 +1119,7 @@ def verify_email_api(): session_: SessionContainer = g.supertokens # type: ignore body: Dict[str, Any] = request.get_json() # type: ignore create_new_role_or_add_permissions(body["role"], body["permissions"]) - add_role_to_user(session_.get_user_id(), body["role"]) + add_role_to_user("public", session_.get_user_id(), body["role"]) session_.sync_fetch_and_set_claim(UserRoleClaim) session_.sync_fetch_and_set_claim(PermissionClaim) return jsonify({"status": "OK"}) diff --git a/tests/emailpassword/test_emaildelivery.py b/tests/emailpassword/test_emaildelivery.py index 5a639d4c7..a391174b0 100644 --- a/tests/emailpassword/test_emaildelivery.py +++ b/tests/emailpassword/test_emaildelivery.py @@ -610,7 +610,7 @@ async def test_email_verification_default_backward_compatibility( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) def api_side_effect(request: httpx.Request): @@ -676,7 +676,7 @@ async def test_email_verification_default_backward_compatibility_suppress_error( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) def api_side_effect(request: httpx.Request): @@ -759,7 +759,7 @@ async def send_email( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) res = email_verify_token_request( @@ -830,7 +830,7 @@ async def send_email( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) def api_side_effect(request: httpx.Request): @@ -962,7 +962,7 @@ async def send_email_override( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) resp = email_verify_token_request( diff --git a/tests/emailpassword/test_emailexists.py b/tests/emailpassword/test_emailexists.py index 84aa9b1cf..5f9caec03 100644 --- a/tests/emailpassword/test_emailexists.py +++ b/tests/emailpassword/test_emailexists.py @@ -50,7 +50,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session(request, user_id, {}, {}) + await create_new_session("public", request, user_id, {}, {}) return {"userId": user_id} @app.post("/refresh") diff --git a/tests/emailpassword/test_emailverify.py b/tests/emailpassword/test_emailverify.py index 21169e80d..03fc8cb43 100644 --- a/tests/emailpassword/test_emailverify.py +++ b/tests/emailpassword/test_emailverify.py @@ -79,7 +79,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session(request, user_id, {}, {}) + await create_new_session("public", request, user_id, {}, {}) return {"userId": user_id} @app.post("/refresh") @@ -192,9 +192,9 @@ async def test_the_generate_token_api_with_valid_input_email_verified_and_test_e user_id = dict_response["user"]["id"] cookies = extract_all_cookies(response_1) - verify_token = await create_email_verification_token(user_id) + verify_token = await create_email_verification_token("public", user_id) if isinstance(verify_token, CreateEmailVerificationTokenOkResult): - await verify_email_using_token(verify_token.token) + await verify_email_using_token("public", verify_token.token) response = email_verify_token_request( driver_config_client, @@ -1101,11 +1101,11 @@ async def test_the_generate_token_api_with_valid_input_and_then_remove_token( assert dict_response["status"] == "OK" user_id = dict_response["user"]["id"] - verify_token = await create_email_verification_token(user_id) - await revoke_email_verification_tokens(user_id) + verify_token = await create_email_verification_token("public", user_id) + await revoke_email_verification_tokens("public", user_id) if isinstance(verify_token, CreateEmailVerificationTokenOkResult): - response = await verify_email_using_token(verify_token.token) + response = await verify_email_using_token("public", verify_token.token) assert isinstance(response, VerifyEmailUsingTokenInvalidTokenError) return raise Exception("Test failed") @@ -1145,9 +1145,9 @@ async def test_the_generate_token_api_with_valid_input_verify_and_then_unverify_ assert dict_response["status"] == "OK" user_id = dict_response["user"]["id"] - verify_token = await create_email_verification_token(user_id) + verify_token = await create_email_verification_token("public", user_id) if isinstance(verify_token, CreateEmailVerificationTokenOkResult): - await verify_email_using_token(verify_token.token) + await verify_email_using_token("public", verify_token.token) assert await is_email_verified(user_id) @@ -1249,9 +1249,9 @@ async def send_email( cookies = extract_all_cookies(res) # Start verification: - verify_token = await create_email_verification_token(user_id) + verify_token = await create_email_verification_token("public", user_id) assert isinstance(verify_token, CreateEmailVerificationTokenOkResult) - await verify_email_using_token(verify_token.token) + await verify_email_using_token("public", verify_token.token) res = email_verify_token_request( driver_config_client, diff --git a/tests/emailpassword/test_multitenancy.py b/tests/emailpassword/test_multitenancy.py index f7cc55baa..eaa87d5bd 100644 --- a/tests/emailpassword/test_multitenancy.py +++ b/tests/emailpassword/test_multitenancy.py @@ -66,9 +66,9 @@ async def test_multitenancy_in_emailpassword(): await create_or_update_tenant("t2", TenantConfig(email_password_enabled=True)) await create_or_update_tenant("t3", TenantConfig(email_password_enabled=True)) - user1 = await sign_up("test@example.com", "password1", "t1") - user2 = await sign_up("test@example.com", "password2", "t2") - user3 = await sign_up("test@example.com", "password3", "t3") + user1 = await sign_up("t1", "test@example.com", "password1") + user2 = await sign_up("t2", "test@example.com", "password2") + user3 = await sign_up("t3", "test@example.com", "password3") assert isinstance(user1, SignUpOkResult) assert isinstance(user2, SignUpOkResult) @@ -83,9 +83,9 @@ async def test_multitenancy_in_emailpassword(): assert user3.user.tenant_ids == ["t3"] # sign in - ep_user1 = await sign_in("test@example.com", "password1", "t1") - ep_user2 = await sign_in("test@example.com", "password2", "t2") - ep_user3 = await sign_in("test@example.com", "password3", "t3") + ep_user1 = await sign_in("t1", "test@example.com", "password1") + ep_user2 = await sign_in("t2", "test@example.com", "password2") + ep_user3 = await sign_in("t3", "test@example.com", "password3") assert isinstance(ep_user1, SignInOkResult) assert isinstance(ep_user2, SignInOkResult) @@ -105,18 +105,18 @@ async def test_multitenancy_in_emailpassword(): assert g_user3 == user3.user # get user by email: - by_email_user1 = await get_user_by_email("test@example.com", "t1") - by_email_user2 = await get_user_by_email("test@example.com", "t2") - by_email_user3 = await get_user_by_email("test@example.com", "t3") + by_email_user1 = await get_user_by_email("t1", "test@example.com") + by_email_user2 = await get_user_by_email("t2", "test@example.com") + by_email_user3 = await get_user_by_email("t3", "test@example.com") assert by_email_user1 == user1.user assert by_email_user2 == user2.user assert by_email_user3 == user3.user # create password reset token: - pless_reset_link1 = await create_reset_password_token(user1.user.user_id, "t1") - pless_reset_link2 = await create_reset_password_token(user2.user.user_id, "t2") - pless_reset_link3 = await create_reset_password_token(user3.user.user_id, "t3") + pless_reset_link1 = await create_reset_password_token("t1", user1.user.user_id) + pless_reset_link2 = await create_reset_password_token("t2", user2.user.user_id) + pless_reset_link3 = await create_reset_password_token("t3", user3.user.user_id) assert isinstance(pless_reset_link1, CreateResetPasswordOkResult) assert isinstance(pless_reset_link2, CreateResetPasswordOkResult) @@ -127,14 +127,14 @@ async def test_multitenancy_in_emailpassword(): assert pless_reset_link3.token is not None # reset password using token: - await reset_password_using_token(pless_reset_link1.token, "newpassword1", "t1") - await reset_password_using_token(pless_reset_link2.token, "newpassword2", "t2") - await reset_password_using_token(pless_reset_link3.token, "newpassword3", "t3") + await reset_password_using_token("t1", pless_reset_link1.token, "newpassword1") + await reset_password_using_token("t2", pless_reset_link2.token, "newpassword2") + await reset_password_using_token("t3", pless_reset_link3.token, "newpassword3") # new password should work: - s_user1 = await sign_in("test@example.com", "newpassword1", "t1") - s_user2 = await sign_in("test@example.com", "newpassword2", "t2") - s_user3 = await sign_in("test@example.com", "newpassword3", "t3") + s_user1 = await sign_in("t1", "test@example.com", "newpassword1") + s_user2 = await sign_in("t2", "test@example.com", "newpassword2") + s_user3 = await sign_in("t3", "test@example.com", "newpassword3") assert isinstance(s_user1, SignInOkResult) assert isinstance(s_user2, SignInOkResult) diff --git a/tests/emailpassword/test_passwordreset.py b/tests/emailpassword/test_passwordreset.py index 5bb13d767..3fd4d3615 100644 --- a/tests/emailpassword/test_passwordreset.py +++ b/tests/emailpassword/test_passwordreset.py @@ -50,7 +50,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session(request, user_id, {}, {}) + await create_new_session("public", request, user_id, {}, {}) return {"userId": user_id} @app.post("/refresh") diff --git a/tests/emailpassword/test_signin.py b/tests/emailpassword/test_signin.py index fa43a5e87..5206318d9 100644 --- a/tests/emailpassword/test_signin.py +++ b/tests/emailpassword/test_signin.py @@ -60,7 +60,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session(request, user_id, {}, {}) + await create_new_session("public", request, user_id, {}, {}) return {"userId": user_id} @app.post("/refresh") diff --git a/tests/frontendIntegration/django2x/polls/views.py b/tests/frontendIntegration/django2x/polls/views.py index 079f57493..0c1ecd230 100644 --- a/tests/frontendIntegration/django2x/polls/views.py +++ b/tests/frontendIntegration/django2x/polls/views.py @@ -396,7 +396,7 @@ def login(request: HttpRequest): if request.method == "POST": user_id = json.loads(request.body)["userId"] - session_ = create_new_session(request, user_id) + session_ = create_new_session("public", request, user_id) return HttpResponse(session_.get_user_id()) else: return send_options_api_response() diff --git a/tests/frontendIntegration/django3x/polls/views.py b/tests/frontendIntegration/django3x/polls/views.py index c91f34b22..d61f5842b 100644 --- a/tests/frontendIntegration/django3x/polls/views.py +++ b/tests/frontendIntegration/django3x/polls/views.py @@ -400,7 +400,7 @@ async def login(request: HttpRequest): if request.method == "POST": user_id = json.loads(request.body)["userId"] - session_ = await create_new_session(request, user_id) + session_ = await create_new_session("public", request, user_id) return HttpResponse(session_.get_user_id()) else: return send_options_api_response() diff --git a/tests/frontendIntegration/fastapi-server/app.py b/tests/frontendIntegration/fastapi-server/app.py index f48f18a52..1dfd11f2d 100644 --- a/tests/frontendIntegration/fastapi-server/app.py +++ b/tests/frontendIntegration/fastapi-server/app.py @@ -265,7 +265,7 @@ def login_options(): @app.post("/login") async def login(request: Request): user_id = (await request.json())["userId"] - _session = await create_new_session(request, user_id) + _session = await create_new_session("public", request, user_id) return PlainTextResponse(content=_session.get_user_id()) diff --git a/tests/frontendIntegration/flask-server/app.py b/tests/frontendIntegration/flask-server/app.py index 6f8c3c282..6edc21cfc 100644 --- a/tests/frontendIntegration/flask-server/app.py +++ b/tests/frontendIntegration/flask-server/app.py @@ -287,7 +287,7 @@ def login_options(): @app.route("/login", methods=["POST"]) # type: ignore def login(): user_id: str = request.get_json()["userId"] # type: ignore - _session = create_new_session(request, user_id) + _session = create_new_session("public", request, user_id) return _session.get_user_id() diff --git a/tests/jwt/test_get_JWKS.py b/tests/jwt/test_get_JWKS.py index 49229c5cb..91e4d7c4b 100644 --- a/tests/jwt/test_get_JWKS.py +++ b/tests/jwt/test_get_JWKS.py @@ -49,7 +49,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session(request, user_id, {}, {}) + await create_new_session("public", request, user_id, {}, {}) return {"userId": user_id} return TestClient(app) diff --git a/tests/multitenancy/test_tenants_crud.py b/tests/multitenancy/test_tenants_crud.py index e410008a8..e39dd87f5 100644 --- a/tests/multitenancy/test_tenants_crud.py +++ b/tests/multitenancy/test_tenants_crud.py @@ -245,7 +245,7 @@ async def test_user_association_and_disassociation_with_tenants(): await create_or_update_tenant("t2", TenantConfig(passwordless_enabled=True)) await create_or_update_tenant("t3", TenantConfig(third_party_enabled=True)) - signup_response = await sign_up("test@example.com", "password1") + signup_response = await sign_up("public", "test@example.com", "password1") assert isinstance(signup_response, SignUpOkResult) user_id = signup_response.user.user_id diff --git a/tests/passwordless/test_mutlitenancy.py b/tests/passwordless/test_mutlitenancy.py index db93eefde..1121b11da 100644 --- a/tests/passwordless/test_mutlitenancy.py +++ b/tests/passwordless/test_mutlitenancy.py @@ -62,32 +62,32 @@ async def test_multitenancy_functions(): await create_or_update_tenant("t3", TenantConfig(passwordless_enabled=True)) code1 = await create_code( - email="test@example.com", user_input_code="123456", tenant_id="t1" + tenant_id="t1", email="test@example.com", user_input_code="123456" ) code2 = await create_code( - email="test@example.com", user_input_code="456789", tenant_id="t2" + tenant_id="t2", email="test@example.com", user_input_code="456789" ) code3 = await create_code( - email="test@example.com", user_input_code="789123", tenant_id="t3" + tenant_id="t3", email="test@example.com", user_input_code="789123" ) user1 = await consume_code( + tenant_id="t1", pre_auth_session_id=code1.pre_auth_session_id, - device_id=code1.device_id, user_input_code="123456", - tenant_id="t1", + device_id=code1.device_id, ) user2 = await consume_code( + tenant_id="t2", pre_auth_session_id=code2.pre_auth_session_id, - device_id=code2.device_id, user_input_code="456789", - tenant_id="t2", + device_id=code2.device_id, ) user3 = await consume_code( + tenant_id="t3", pre_auth_session_id=code3.pre_auth_session_id, - device_id=code3.device_id, user_input_code="789123", - tenant_id="t3", + device_id=code3.device_id, ) assert isinstance(user1, ConsumeCodeOkResult) @@ -112,9 +112,9 @@ async def test_multitenancy_functions(): assert g_user3 == user3.user # get user by email: - by_email_user1 = await get_user_by_email("test@example.com", "t1") - by_email_user2 = await get_user_by_email("test@example.com", "t2") - by_email_user3 = await get_user_by_email("test@example.com", "t3") + by_email_user1 = await get_user_by_email("t1", "test@example.com") + by_email_user2 = await get_user_by_email("t2", "test@example.com") + by_email_user3 = await get_user_by_email("t3", "test@example.com") assert by_email_user1 == user1.user assert by_email_user2 == user2.user diff --git a/tests/sessions/claims/test_create_new_session.py b/tests/sessions/claims/test_create_new_session.py index bd0fb4703..5d32beb6c 100644 --- a/tests/sessions/claims/test_create_new_session.py +++ b/tests/sessions/claims/test_create_new_session.py @@ -28,7 +28,7 @@ async def test_create_access_token_payload_with_session_claims(timestamp: int): start_st() dummy_req: BaseRequest = MagicMock() - s = await create_new_session(dummy_req, "someId") + s = await create_new_session("public", dummy_req, "someId") payload = s.get_access_token_payload() assert len(payload) == 10 @@ -41,7 +41,7 @@ async def test_should_create_access_token_payload_with_session_claims_with_an_no start_st() dummy_req: BaseRequest = MagicMock() - s = await create_new_session(dummy_req, "someId") + s = await create_new_session("public", dummy_req, "someId") payload = s.get_access_token_payload() assert len(payload) == 9 @@ -66,7 +66,7 @@ async def test_should_merge_claims_and_passed_access_token_payload_obj(timestamp start_st() dummy_req: BaseRequest = MagicMock() - s = await create_new_session(dummy_req, "someId") + s = await create_new_session("public", dummy_req, "someId") payload = s.get_access_token_payload() assert len(payload) == 10 diff --git a/tests/sessions/claims/test_get_claim_value.py b/tests/sessions/claims/test_get_claim_value.py index 1825fac14..0fa5bafdb 100644 --- a/tests/sessions/claims/test_get_claim_value.py +++ b/tests/sessions/claims/test_get_claim_value.py @@ -28,7 +28,7 @@ async def test_should_get_the_right_value(): start_st() dummy_req: BaseRequest = MagicMock() - s = await create_new_session(dummy_req, "someId") + s = await create_new_session("public", dummy_req, "someId") res = await s.get_claim_value(TrueClaim) assert res is True @@ -39,7 +39,7 @@ async def test_should_get_the_right_value_using_session_handle(): start_st() dummy_req: BaseRequest = MagicMock() - s: SessionContainer = await create_new_session(dummy_req, "someId") + s: SessionContainer = await create_new_session("public", dummy_req, "someId") res = await get_claim_value(s.get_handle(), TrueClaim) assert isinstance(res, GetClaimValueOkResult) diff --git a/tests/sessions/claims/test_remove_claim.py b/tests/sessions/claims/test_remove_claim.py index 9231e614f..99417b67d 100644 --- a/tests/sessions/claims/test_remove_claim.py +++ b/tests/sessions/claims/test_remove_claim.py @@ -56,7 +56,7 @@ async def test_should_clear_previously_set_claim(timestamp: int): start_st() dummy_req: BaseRequest = MagicMock() - s: SessionContainer = await create_new_session(dummy_req, "someId") + s: SessionContainer = await create_new_session("public", dummy_req, "someId") payload = s.get_access_token_payload() @@ -68,7 +68,7 @@ async def test_should_clear_previously_set_claim_using_handle(timestamp: int): start_st() dummy_req: BaseRequest = MagicMock() - s: SessionContainer = await create_new_session(dummy_req, "someId") + s: SessionContainer = await create_new_session("public", dummy_req, "someId") payload = s.get_access_token_payload() assert payload["st-true"] == {"v": True, "t": timestamp} diff --git a/tests/sessions/claims/test_set_claim_value.py b/tests/sessions/claims/test_set_claim_value.py index b8b78e734..9e958b9ad 100644 --- a/tests/sessions/claims/test_set_claim_value.py +++ b/tests/sessions/claims/test_set_claim_value.py @@ -57,7 +57,7 @@ async def test_should_overwrite_claim_value(timestamp: int): start_st() dummy_req: BaseRequest = MagicMock() - s = await create_new_session(dummy_req, "someId") + s = await create_new_session("public", dummy_req, "someId") payload = s.get_access_token_payload() assert len(payload) == 9 @@ -76,7 +76,7 @@ async def test_should_overwrite_claim_value_using_session_handle(timestamp: int) start_st() dummy_req: BaseRequest = MagicMock() - s = await create_new_session(dummy_req, "someId") + s = await create_new_session("public", dummy_req, "someId") payload = s.get_access_token_payload() assert len(payload) == 9 diff --git a/tests/sessions/claims/test_validate_claims_for_session_handle.py b/tests/sessions/claims/test_validate_claims_for_session_handle.py index 4fcc89912..35edaa6b8 100644 --- a/tests/sessions/claims/test_validate_claims_for_session_handle.py +++ b/tests/sessions/claims/test_validate_claims_for_session_handle.py @@ -31,7 +31,7 @@ async def test_should_return_the_right_validation_errors(): start_st() dummy_req: BaseRequest = MagicMock() - s = await create_new_session(dummy_req, "someId") + s = await create_new_session("public", dummy_req, "someId") failing_validator = NoneClaim.validators.has_value(True) res = await validate_claims_for_session_handle( diff --git a/tests/sessions/claims/test_verify_session.py b/tests/sessions/claims/test_verify_session.py index cdf014a3a..fe5bb5d83 100644 --- a/tests/sessions/claims/test_verify_session.py +++ b/tests/sessions/claims/test_verify_session.py @@ -134,13 +134,13 @@ async def fastapi_client(): @app.post("/login") async def _login(request: Request): # type: ignore user_id = "userId" - await create_new_session(request, user_id, {}, {}) + await create_new_session("public", request, user_id, {}, {}) return {"userId": user_id} @app.post("/create-with-claim") async def _create_with_claim(request: Request): # type: ignore user_id = "userId" - _ = await create_new_session(request, user_id, {}, {}) + _ = await create_new_session("public", request, user_id, {}, {}) key: str = (await request.json())["key"] # PrimitiveClaim(key, fetch_value="Value").add_to_session(session, "value") return {"userId": key} diff --git a/tests/sessions/test_access_token_v3.py b/tests/sessions/test_access_token_v3.py index 0ca1efc8e..dd9e72265 100644 --- a/tests/sessions/test_access_token_v3.py +++ b/tests/sessions/test_access_token_v3.py @@ -26,7 +26,7 @@ async def test_access_token_v4(): start_st() access_token = ( - await create_new_session_without_request_response("user-id") + await create_new_session_without_request_response("public", "user-id") ).get_access_token() s = await get_session_without_request_response(access_token) assert s is not None @@ -74,7 +74,7 @@ async def _create(request: Request): # type: ignore except Exception: pass - session = await create_new_session(request, "userId", body, {}) + session = await create_new_session("public", request, "userId", body, {}) return {"message": True, "sessionHandle": session.get_handle()} @fast.get("/merge-into-payload") diff --git a/tests/sessions/test_auth_mode.py b/tests/sessions/test_auth_mode.py index 9bdda9cd3..d38f215ab 100644 --- a/tests/sessions/test_auth_mode.py +++ b/tests/sessions/test_auth_mode.py @@ -33,7 +33,7 @@ async def app(): @fast.post("/create") async def _create(request: Request): # type: ignore body = await request.json() - session = await create_new_session(request, "userId", body, {}) + session = await create_new_session("public", request, "userId", body, {}) return {"message": True, "sessionHandle": session.get_handle()} @fast.get("/update-payload") diff --git a/tests/sessions/test_jwks.py b/tests/sessions/test_jwks.py index 7c9a23d0b..523699600 100644 --- a/tests/sessions/test_jwks.py +++ b/tests/sessions/test_jwks.py @@ -79,7 +79,7 @@ async def test_that_jwks_is_fetched_as_expected(caplog: LogCaptureFixture): assert next(well_known_count) == 0 - s = await create_new_session_without_request_response("userId", {}, {}) + s = await create_new_session_without_request_response("public", "userId", {}, {}) time.sleep(JWKSConfig["cache_max_age"] / 1000) tokens = s.get_all_session_tokens_dangerously() @@ -168,7 +168,7 @@ async def test_that_jwks_are_refresh_if_kid_is_unknown(caplog: LogCaptureFixture assert next(well_known_count) == 0 - s = await create_new_session_without_request_response("userId", {}, {}) + s = await create_new_session_without_request_response("public", "userId", {}, {}) assert next(well_known_count) == 0 @@ -183,7 +183,7 @@ async def test_that_jwks_are_refresh_if_kid_is_unknown(caplog: LogCaptureFixture assert next(well_known_count) == 1 - s = await create_new_session_without_request_response("userId", {}, {}) + s = await create_new_session_without_request_response("public", "userId", {}, {}) assert next(well_known_count) == 1 @@ -254,7 +254,7 @@ async def test_jwks_cache_logic(caplog: LogCaptureFixture): assert next(jwks_refresh_count) == 0 - s = await create_new_session_without_request_response("userId", {}, {}) + s = await create_new_session_without_request_response("public", "userId", {}, {}) assert get_cached_keys() is None assert next(jwks_refresh_count) == 0 @@ -380,7 +380,7 @@ async def test_that_jwks_returns_from_cache_correctly(caplog: LogCaptureFixture) init(**get_st_init_args(recipe_list=[session.init()])) start_st() - s = await create_new_session_without_request_response("userId", {}, {}) + s = await create_new_session_without_request_response("public", "userId", {}, {}) assert get_cached_keys() is None assert next(jwk_refresh_count) == 0 assert next(returned_from_cache_count) == 0 @@ -475,7 +475,7 @@ async def test_session_verification_of_jwt_based_on_session_payload( init(**get_st_init_args(recipe_list=[session.init()])) start_st() - s = await create_new_session_without_request_response("userId", {}, {}) + s = await create_new_session_without_request_response("public", "userId", {}, {}) payload = s.get_access_token_payload() del payload["iat"] @@ -497,7 +497,7 @@ async def test_session_verification_of_jwt_based_on_session_payload_with_check_d init(**get_st_init_args(recipe_list=[session.init()])) start_st() - s = await create_new_session_without_request_response("userId", {}, {}) + s = await create_new_session_without_request_response("public", "userId", {}, {}) payload = s.get_access_token_payload() del payload["iat"] @@ -521,7 +521,7 @@ async def test_session_verification_of_jwt_with_dynamic_signing_key(): ) start_st() - s = await create_new_session_without_request_response("userId", {}, {}) + s = await create_new_session_without_request_response("public", "userId", {}, {}) payload = s.get_access_token_payload() del payload["iat"] diff --git a/tests/supertokens_python/test_supertokens_functions.py b/tests/supertokens_python/test_supertokens_functions.py index b4dfc0dcc..d33299a61 100644 --- a/tests/supertokens_python/test_supertokens_functions.py +++ b/tests/supertokens_python/test_supertokens_functions.py @@ -59,7 +59,7 @@ async def test_supertokens_functions(): emails = [f"{u}@example.com" for u in ["foo", "bar", "baz"]] user_ids: List[str] = [] for e in emails: - signup_resp = await ep_asyncio.sign_up(e, "secret_pass") + signup_resp = await ep_asyncio.sign_up("public", e, "secret_pass") assert isinstance(signup_resp, SignUpOkResult) user_ids.append(signup_resp.user.user_id) @@ -67,12 +67,12 @@ async def test_supertokens_functions(): assert await st_asyncio.get_user_count() == len(emails) # Get users in ascending order by joining time - users_asc = (await st_asyncio.get_users_oldest_first(limit=10)).users + users_asc = (await st_asyncio.get_users_oldest_first("public", limit=10)).users emails_asc = [user.email for user in users_asc] assert emails_asc == emails # Get users in descending order by joining time - users_desc = (await st_asyncio.get_users_newest_first(limit=10)).users + users_desc = (await st_asyncio.get_users_newest_first("public", limit=10)).users emails_desc = [user.email for user in users_desc] assert emails_desc == emails[::-1] @@ -86,7 +86,7 @@ async def test_supertokens_functions(): # Again, get users in ascending order by joining time # We expect that the 2nd user (bar@example.com) must be absent. - users_asc = (await st_asyncio.get_users_oldest_first(limit=10)).users + users_asc = (await st_asyncio.get_users_oldest_first("public", limit=10)).users emails_asc = [user.email for user in users_asc] assert emails[1] not in emails_asc # The 2nd user must be deleted now. @@ -94,10 +94,14 @@ async def test_supertokens_functions(): # If the version is less than 2.20, query users doesn't exist, so we mark the test successful return users_asc = ( - await st_asyncio.get_users_oldest_first(limit=10, query={"email": "baz"}) + await st_asyncio.get_users_oldest_first( + "public", limit=10, query={"email": "baz"} + ) ).users users_desc = ( - await st_asyncio.get_users_newest_first(limit=10, query={"email": "baz"}) + await st_asyncio.get_users_newest_first( + "public", limit=10, query={"email": "baz"} + ) ).users emails_asc = [user.email for user in users_asc] emails_desc = [user.email for user in users_desc] @@ -105,10 +109,14 @@ async def test_supertokens_functions(): assert len(emails_desc) == 1 users_asc = ( - await st_asyncio.get_users_oldest_first(limit=10, query={"email": "john"}) + await st_asyncio.get_users_oldest_first( + "public", limit=10, query={"email": "john"} + ) ).users users_desc = ( - await st_asyncio.get_users_newest_first(limit=10, query={"email": "john"}) + await st_asyncio.get_users_newest_first( + "public", limit=10, query={"email": "john"} + ) ).users emails_asc = [user.email for user in users_asc] emails_desc = [user.email for user in users_desc] diff --git a/tests/test_config.py b/tests/test_config.py index 0d3a590f2..521827f99 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -728,7 +728,7 @@ async def test_samesite_invalid_config(): ) ], ) - await create_new_session(MagicMock(), "userId", {}, {}) + await create_new_session("public", MagicMock(), "userId", {}, {}) except Exception as e: assert ( str(e) diff --git a/tests/test_pagination.py b/tests/test_pagination.py index 5730b1f5b..d66b9163b 100644 --- a/tests/test_pagination.py +++ b/tests/test_pagination.py @@ -47,20 +47,20 @@ async def test_get_users_pagination(): start_st() for i in range(5): - await sign_up(f"dummy{i}@gmail.com", "validpass123") + await sign_up("public", f"dummy{i}@gmail.com", "validpass123") # Get all the users (No limit) - response = await get_users_newest_first() + response = await get_users_newest_first("public") assert [user.email for user in response.users] == [ f"dummy{i}@gmail.com" for i in range(5) ][::-1] # Get only the oldest user - response = await get_users_oldest_first(limit=1) + response = await get_users_oldest_first("public", limit=1) assert [user.email for user in response.users] == ["dummy0@gmail.com"] # Test pagination response = await get_users_oldest_first( - limit=1, pagination_token=response.next_pagination_token + "public", limit=1, pagination_token=response.next_pagination_token ) assert [user.email for user in response.users] == ["dummy1@gmail.com"] diff --git a/tests/test_passwordless.py b/tests/test_passwordless.py index 9f9e1fd28..b4ab138f3 100644 --- a/tests/test_passwordless.py +++ b/tests/test_passwordless.py @@ -200,7 +200,7 @@ async def send_sms( response = await delete_phone_number_for_user(user_id) assert isinstance(response, DeleteUserInfoOkResult) - user = await get_user_by_phone_number("+919494949494") + user = await get_user_by_phone_number("public", "+919494949494") assert user is None user = await get_user_by_id(user_id) @@ -283,7 +283,7 @@ async def send_sms( response = await delete_email_for_user(user_id) assert isinstance(response, DeleteUserInfoOkResult) - user = await get_user_by_email("hello@example.com") + user = await get_user_by_email("public", "hello@example.com") assert user is None user = await get_user_by_id(user_id) diff --git a/tests/test_session.py b/tests/test_session.py index ff123334e..fd803e312 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -91,7 +91,7 @@ async def test_that_once_the_info_is_loaded_it_doesnt_query_again(): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, "", False, {}, {}, "public" + s.recipe_implementation, "public", "", False, {}, {} ) assert response.session is not None @@ -190,11 +190,11 @@ async def test_creating_many_sessions_for_one_user_and_looping(): for _ in range(7): new_session = await create_new_session( s.recipe_implementation, + "public", "someUser", False, {"someKey": "someValue"}, {}, - "public", ) access_tokens.append(new_session.accessToken.token) @@ -255,7 +255,7 @@ async def home(_request: Request): # type: ignore @app.post("/create") async def create_api(request: Request): # type: ignore - await async_create_new_session(request, "test-user", {}, {}) + await async_create_new_session("public", request, "test-user", {}, {}) return "" return TestClient(app) @@ -282,7 +282,7 @@ async def test_signout_api_works_even_if_session_is_deleted_after_creation( user_id = "user_id" response = await create_new_session( - s.recipe_implementation, user_id, False, {}, {}, None + s.recipe_implementation, "public", user_id, False, {}, {} ) session_handle = response.session.handle @@ -347,7 +347,7 @@ async def get_session_information( mock_response = MagicMock() - my_session = await async_create_new_session(mock_response, "test_id") + my_session = await async_create_new_session("public", mock_response, "test_id") data = await my_session.get_session_data_from_database() assert data == {"foo": "bar"} @@ -680,7 +680,7 @@ async def test_that_verify_session_doesnt_always_call_core(): # response = await create_new_session(s.recipe_implementation, "", False, {}, {}) - session1 = await create_new_session_without_request_response("user-id") + session1 = await create_new_session_without_request_response("public", "user-id") assert session1 is not None assert session1.access_token != "" diff --git a/tests/test_thirdpartypasswordless_delete_user.py b/tests/test_thirdpartypasswordless_delete_user.py index cfc1f9eba..46d943bab 100644 --- a/tests/test_thirdpartypasswordless_delete_user.py +++ b/tests/test_thirdpartypasswordless_delete_user.py @@ -139,7 +139,7 @@ async def send_sms( response = await delete_phone_number_for_user(user_id) assert isinstance(response, DeleteUserInfoOkResult) - user = await get_user_by_phone_number("+919494949494") + user = await get_user_by_phone_number("public", "+919494949494") assert user is None user = await get_user_by_id(user_id) @@ -154,7 +154,7 @@ async def send_sms( response = await delete_email_for_passwordless_user(user_id) assert isinstance(response, DeleteUserInfoOkResult) - users = await get_users_by_email("foo@example.com") + users = await get_users_by_email("public", "foo@example.com") assert users == [] user = await get_user_by_id(user_id) diff --git a/tests/test_user_context.py b/tests/test_user_context.py index e361ff6ee..91e852fc9 100644 --- a/tests/test_user_context.py +++ b/tests/test_user_context.py @@ -182,7 +182,7 @@ async def create_new_session( ) start_st() - await sign_up("random@gmail.com", "validpass123", "public", {"manualCall": True}) + await sign_up("public", "random@gmail.com", "validpass123", {"manualCall": True}) res = sign_in_request(driver_config_client, "random@gmail.com", "validpass123") assert res.status_code == 200 @@ -288,7 +288,7 @@ async def create_new_session( ) start_st() - await sign_up("random@gmail.com", "validpass123", "public", {"manualCall": True}) + await sign_up("public", "random@gmail.com", "validpass123", {"manualCall": True}) res = sign_in_request(driver_config_client, "random@gmail.com", "validpass123") assert res.status_code == 200 @@ -413,7 +413,7 @@ async def create_new_session( ) start_st() - await sign_up("random@gmail.com", "validpass123", "public", {"manualCall": True}) + await sign_up("public", "random@gmail.com", "validpass123", {"manualCall": True}) res = sign_in_request(driver_config_client, "random@gmail.com", "validpass123") assert res.status_code == 200 diff --git a/tests/thirdparty/test_emaildelivery.py b/tests/thirdparty/test_emaildelivery.py index 4761e1f7c..52a020f41 100644 --- a/tests/thirdparty/test_emaildelivery.py +++ b/tests/thirdparty/test_emaildelivery.py @@ -139,7 +139,7 @@ async def test_email_verify_default_backward_compatibility( start_st() resp = await manually_create_or_update_user( - "supertokens", "test-user-id", "test@example.com" + "public", "supertokens", "test-user-id", "test@example.com" ) s = SessionRecipe.get_instance() @@ -148,7 +148,7 @@ async def test_email_verify_default_backward_compatibility( assert isinstance(resp, ManuallyCreateOrUpdateUserOkResult) user_id = resp.user.user_id response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) def api_side_effect(request: httpx.Request): @@ -213,7 +213,7 @@ async def test_email_verify_default_backward_compatibility_supress_error( start_st() resp = await manually_create_or_update_user( - "supertokens", "test-user-id", "test@example.com" + "public", "supertokens", "test-user-id", "test@example.com" ) s = SessionRecipe.get_instance() @@ -222,7 +222,7 @@ async def test_email_verify_default_backward_compatibility_supress_error( assert isinstance(resp, ManuallyCreateOrUpdateUserOkResult) user_id = resp.user.user_id response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) def api_side_effect(request: httpx.Request): @@ -303,7 +303,7 @@ async def send_email( start_st() resp = await manually_create_or_update_user( - "supertokens", "test-user-id", "test@example.com" + "public", "supertokens", "test-user-id", "test@example.com" ) s = SessionRecipe.get_instance() @@ -312,7 +312,7 @@ async def send_email( assert isinstance(resp, ManuallyCreateOrUpdateUserOkResult) user_id = resp.user.user_id response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) resp = email_verify_token_request( @@ -381,7 +381,7 @@ async def send_email( start_st() resp = await manually_create_or_update_user( - "supertokens", "test-user-id", "test@example.com" + "public", "supertokens", "test-user-id", "test@example.com" ) s = SessionRecipe.get_instance() @@ -391,7 +391,7 @@ async def send_email( user_id = resp.user.user_id assert isinstance(user_id, str) response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) def api_side_effect(request: httpx.Request): @@ -521,7 +521,7 @@ async def send_email_override( start_st() resp = await manually_create_or_update_user( - "supertokens", "test-user-id", "test@example.com" + "public", "supertokens", "test-user-id", "test@example.com" ) s = SessionRecipe.get_instance() @@ -531,7 +531,7 @@ async def send_email_override( user_id = resp.user.user_id assert isinstance(user_id, str) response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) resp = email_verify_token_request( diff --git a/tests/thirdparty/test_multitenancy.py b/tests/thirdparty/test_multitenancy.py index a9c626c8b..c1785d881 100644 --- a/tests/thirdparty/test_multitenancy.py +++ b/tests/thirdparty/test_multitenancy.py @@ -55,22 +55,22 @@ async def test_thirtyparty_multitenancy_functions(): # sign up: user1a = await manually_create_or_update_user( - "google", "googleid1", "test@example.com", "t1" + "t1", "google", "googleid1", "test@example.com" ) user1b = await manually_create_or_update_user( - "facebook", "fbid1", "test@example.com", "t1" + "t1", "facebook", "fbid1", "test@example.com" ) user2a = await manually_create_or_update_user( - "google", "googleid1", "test@example.com", "t2" + "t2", "google", "googleid1", "test@example.com" ) user2b = await manually_create_or_update_user( - "facebook", "fbid1", "test@example.com", "t2" + "t2", "facebook", "fbid1", "test@example.com" ) user3a = await manually_create_or_update_user( - "google", "googleid1", "test@example.com", "t3" + "t3", "google", "googleid1", "test@example.com" ) user3b = await manually_create_or_update_user( - "facebook", "fbid1", "test@example.com", "t3" + "t3", "facebook", "fbid1", "test@example.com" ) assert user1a.user.tenant_ids == ["t1"] @@ -96,21 +96,21 @@ async def test_thirtyparty_multitenancy_functions(): assert g_user3b == user3b.user # get user by email: - by_email_user1 = await get_users_by_email("test@example.com", "t1") - by_email_user2 = await get_users_by_email("test@example.com", "t2") - by_email_user3 = await get_users_by_email("test@example.com", "t3") + by_email_user1 = await get_users_by_email("t1", "test@example.com") + by_email_user2 = await get_users_by_email("t2", "test@example.com") + by_email_user3 = await get_users_by_email("t3", "test@example.com") assert by_email_user1 == [user1a.user, user1b.user] assert by_email_user2 == [user2a.user, user2b.user] assert by_email_user3 == [user3a.user, user3b.user] # get user by thirdparty id: - g_user_by_tpid1a = await get_user_by_third_party_info("google", "googleid1", "t1") - g_user_by_tpid1b = await get_user_by_third_party_info("facebook", "fbid1", "t1") - g_user_by_tpid2a = await get_user_by_third_party_info("google", "googleid1", "t2") - g_user_by_tpid2b = await get_user_by_third_party_info("facebook", "fbid1", "t2") - g_user_by_tpid3a = await get_user_by_third_party_info("google", "googleid1", "t3") - g_user_by_tpid3b = await get_user_by_third_party_info("facebook", "fbid1", "t3") + g_user_by_tpid1a = await get_user_by_third_party_info("t1", "google", "googleid1") + g_user_by_tpid1b = await get_user_by_third_party_info("t1", "facebook", "fbid1") + g_user_by_tpid2a = await get_user_by_third_party_info("t2", "google", "googleid1") + g_user_by_tpid2b = await get_user_by_third_party_info("t2", "facebook", "fbid1") + g_user_by_tpid3a = await get_user_by_third_party_info("t3", "google", "googleid1") + g_user_by_tpid3b = await get_user_by_third_party_info("t3", "facebook", "fbid1") assert g_user_by_tpid1a == user1a.user assert g_user_by_tpid1b == user1b.user @@ -200,20 +200,20 @@ async def test_get_provider(): ), ) - provider1 = await get_provider("google", None, "t1") + provider1 = await get_provider("t1", "google", None) assert provider1.provider.config.third_party_id == "google" - provider2 = await get_provider("facebook", None, "t1") + provider2 = await get_provider("t1", "facebook", None) assert provider2.provider.config.third_party_id == "facebook" - provider3 = await get_provider("facebook", None, "t2") + provider3 = await get_provider("t2", "facebook", None) assert provider3.provider.config.third_party_id == "facebook" - provider4 = await get_provider("discord", None, "t2") + provider4 = await get_provider("t2", "discord", None) assert provider4.provider.config.third_party_id == "discord" - provider5 = await get_provider("discord", None, "t3") + provider5 = await get_provider("t3", "discord", None) assert provider5.provider.config.third_party_id == "discord" - provider6 = await get_provider("linkedin", None, "t3") + provider6 = await get_provider("t3", "linkedin", None) assert provider6.provider.config.third_party_id == "linkedin" diff --git a/tests/thirdpartyemailpassword/test_email_delivery.py b/tests/thirdpartyemailpassword/test_email_delivery.py index 76d3aec36..6c2d3eb2c 100644 --- a/tests/thirdpartyemailpassword/test_email_delivery.py +++ b/tests/thirdpartyemailpassword/test_email_delivery.py @@ -504,7 +504,7 @@ async def test_email_verification_default_backward_compatibility( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) def api_side_effect(request: httpx.Request): @@ -570,7 +570,7 @@ async def test_email_verification_default_backward_compatibility_suppress_error( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) def api_side_effect(request: httpx.Request): @@ -654,7 +654,7 @@ async def send_email( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, False, {}, {}, None + s.recipe_implementation, "public", user_id, False, {}, {} ) res = email_verify_token_request( @@ -725,7 +725,7 @@ async def send_email( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) def api_side_effect(request: httpx.Request): @@ -857,7 +857,7 @@ async def send_email_override( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) resp = email_verify_token_request( @@ -934,7 +934,7 @@ async def send_email( start_st() resp = await thirdparty_manually_create_or_update_user( - "supertokens", "test-user-id", "test@example.com" + "public", "supertokens", "test-user-id", "test@example.com" ) user_id: str = resp.user.user_id # type: ignore @@ -942,7 +942,7 @@ async def send_email( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) res = email_verify_token_request( @@ -1013,7 +1013,7 @@ async def send_email( start_st() resp = await thirdparty_manually_create_or_update_user( - "supertokens", "test-user-id", "test@example.com" + "public", "supertokens", "test-user-id", "test@example.com" ) user_id: str = resp.user.user_id # type: ignore @@ -1021,7 +1021,7 @@ async def send_email( if not isinstance(s.recipe_implementation, SessionRecipeImplementation): raise Exception("Should never come here") response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) res = email_verify_token_request( diff --git a/tests/thirdpartypasswordless/test_emaildelivery.py b/tests/thirdpartypasswordless/test_emaildelivery.py index 1611c04ed..b1c749a59 100644 --- a/tests/thirdpartypasswordless/test_emaildelivery.py +++ b/tests/thirdpartypasswordless/test_emaildelivery.py @@ -153,7 +153,7 @@ async def test_email_verify_default_backward_compatibility( start_st() resp = await thirdparty_manually_create_or_update_user( - "supertokens", "test-user-id", "test@example.com" + "public", "supertokens", "test-user-id", "test@example.com" ) s = SessionRecipe.get_instance() @@ -162,7 +162,7 @@ async def test_email_verify_default_backward_compatibility( assert isinstance(resp, ThirdPartyManuallyCreateOrUpdateUserOkResult) user_id = resp.user.user_id response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) def api_side_effect(request: httpx.Request): @@ -252,7 +252,7 @@ async def send_email( start_st() resp = await thirdparty_manually_create_or_update_user( - "supertokens", "test-user-id", "test@example.com" + "public", "supertokens", "test-user-id", "test@example.com" ) s = SessionRecipe.get_instance() @@ -261,7 +261,7 @@ async def send_email( assert isinstance(resp, ThirdPartyManuallyCreateOrUpdateUserOkResult) user_id = resp.user.user_id response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) resp = email_verify_token_request( @@ -341,7 +341,7 @@ async def send_email( start_st() resp = await thirdparty_manually_create_or_update_user( - "supertokens", "test-user-id", "test@example.com" + "public", "supertokens", "test-user-id", "test@example.com" ) s = SessionRecipe.get_instance() @@ -351,7 +351,7 @@ async def send_email( user_id = resp.user.user_id assert isinstance(user_id, str) response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) def api_side_effect(request: httpx.Request): @@ -492,7 +492,7 @@ async def send_email_override( start_st() resp = await thirdparty_manually_create_or_update_user( - "supertokens", "test-user-id", "test@example.com" + "public", "supertokens", "test-user-id", "test@example.com" ) s = SessionRecipe.get_instance() @@ -502,7 +502,7 @@ async def send_email_override( user_id = resp.user.user_id assert isinstance(user_id, str) response = await create_new_session( - s.recipe_implementation, user_id, True, {}, {}, None + s.recipe_implementation, "public", user_id, True, {}, {} ) resp = email_verify_token_request( @@ -612,9 +612,11 @@ async def send_email_override( return pless_response = await passwordlessSigninup( - "test@example.com", None, DEFAULT_TENANT_ID, {} + DEFAULT_TENANT_ID, "test@example.com", None, {} + ) + create_token = await create_email_verification_token( + "public", pless_response.user.user_id ) - create_token = await create_email_verification_token(pless_response.user.user_id) assert isinstance(create_token, CreateEmailVerificationTokenOkResult) # TODO: Replaced CreateEmailVerificationTokenEmailAlreadyVerifiedError. Confirm if this is correct. diff --git a/tests/useridmapping/create_user_id_mapping.py b/tests/useridmapping/create_user_id_mapping.py index 9d1ea359a..a872d413a 100644 --- a/tests/useridmapping/create_user_id_mapping.py +++ b/tests/useridmapping/create_user_id_mapping.py @@ -52,7 +52,7 @@ async def test_create_user_id_mapping(): if not is_version_gte(version, "2.15"): skip() - sign_up_res = await sign_up("test@example.com", "testPass123") + sign_up_res = await sign_up("public", "test@example.com", "testPass123") assert isinstance(sign_up_res, SignUpOkResult) supertokens_user_id = sign_up_res.user.user_id @@ -84,7 +84,7 @@ async def test_create_user_id_mapping_without_and_with_force(): skip() # Create a user: - sign_up_res = await sign_up("test@example.com", "testPass123") + sign_up_res = await sign_up("public", "test@example.com", "testPass123") assert isinstance(sign_up_res, SignUpOkResult) supertokens_user_id = sign_up_res.user.user_id @@ -143,7 +143,7 @@ async def create_user_id_mapping_when_mapping_already_exists(): if not is_version_gte(version, "2.15"): skip() - sign_up_res = await sign_up("test@example.com", "testPass123") + sign_up_res = await sign_up("public", "test@example.com", "testPass123") assert isinstance(sign_up_res, SignUpOkResult) supertokens_user_id = sign_up_res.user.user_id @@ -167,7 +167,7 @@ async def create_user_id_mapping_when_mapping_already_exists(): assert res.does_external_user_id_exist is False # Try creating a duplicate mapping where external_user_id exists and but supertokens_user_id doesn't (new) - sign_up_res = await sign_up("foo@bar.com", "baz") + sign_up_res = await sign_up("public", "foo@bar.com", "baz") assert isinstance(sign_up_res, SignUpOkResult) new_supertokens_user_id = sign_up_res.user.user_id diff --git a/tests/useridmapping/delete_user_id_mapping.py b/tests/useridmapping/delete_user_id_mapping.py index 1a633a72b..0915d6d33 100644 --- a/tests/useridmapping/delete_user_id_mapping.py +++ b/tests/useridmapping/delete_user_id_mapping.py @@ -63,7 +63,7 @@ async def test_delete_user_id_mapping(user_type: USER_TYPE): skip() # Create ST User - sign_up_res = await sign_up("test@example.com", "password") + sign_up_res = await sign_up("public", "test@example.com", "password") assert isinstance(sign_up_res, SignUpOkResult) supertokens_user_id = sign_up_res.user.user_id @@ -101,7 +101,7 @@ async def test_delete_user_id_mapping_without_and_with_force(): skip() # Create a user: - sign_up_res = await sign_up("test@example.com", "testPass123") + sign_up_res = await sign_up("public", "test@example.com", "testPass123") assert isinstance(sign_up_res, SignUpOkResult) supertokens_user_id = sign_up_res.user.user_id diff --git a/tests/useridmapping/get_user_id_mapping.py b/tests/useridmapping/get_user_id_mapping.py index 700ac4012..517d076f4 100644 --- a/tests/useridmapping/get_user_id_mapping.py +++ b/tests/useridmapping/get_user_id_mapping.py @@ -59,7 +59,7 @@ async def test_get_user_id_mapping(use_external_id_info: bool): if not is_version_gte(version, "2.15"): skip() - sign_up_res = await sign_up("test@example.com", "password") + sign_up_res = await sign_up("public", "test@example.com", "password") assert isinstance(sign_up_res, SignUpOkResult) supertokens_user_id = sign_up_res.user.user_id diff --git a/tests/useridmapping/recipe_tests.py b/tests/useridmapping/recipe_tests.py index 477ef6ff0..42e2d1c94 100644 --- a/tests/useridmapping/recipe_tests.py +++ b/tests/useridmapping/recipe_tests.py @@ -52,7 +52,7 @@ def teardown_function(_): async def ep_get_new_user_id(email: str) -> str: from supertokens_python.recipe.emailpassword.asyncio import sign_up - sign_up_res = await sign_up(email, "password") + sign_up_res = await sign_up("public", email, "password") assert isinstance(sign_up_res, SignUpOkResult) return sign_up_res.user.user_id @@ -69,7 +69,7 @@ async def ep_get_existing_user_id(user_id: str) -> str: async def ep_get_existing_user_by_email(email: str) -> str: from supertokens_python.recipe.emailpassword.asyncio import get_user_by_email - res = await get_user_by_email(email) + res = await get_user_by_email("public", email) assert res is not None return res.user_id @@ -77,7 +77,7 @@ async def ep_get_existing_user_by_email(email: str) -> str: async def ep_get_existing_user_by_signin(email: str) -> str: from supertokens_python.recipe.emailpassword.asyncio import sign_in - res = await sign_in(email, "password") + res = await sign_in("public", email, "password") assert isinstance(res, SignInOkResult) return res.user.user_id @@ -89,9 +89,9 @@ async def ep_get_existing_user_after_reset_password(user_id: str) -> str: reset_password_using_token, ) - result = await create_reset_password_token(user_id) + result = await create_reset_password_token("public", user_id) assert isinstance(result, CreateResetPasswordOkResult) - res = await reset_password_using_token(result.token, new_password) + res = await reset_password_using_token("public", result.token, new_password) assert isinstance(res, ResetPasswordUsingTokenOkResult) assert res.user_id is not None return res.user_id @@ -108,7 +108,7 @@ async def ep_get_existing_user_after_updating_email_and_sign_in(user_id: str) -> res = await update_email_or_password(user_id, new_email, "password") assert isinstance(res, SignUpOkResult) - res = await sign_in(new_email, "password") + res = await sign_in("public", new_email, "password") assert isinstance(res, SignInOkResult) return res.user.user_id diff --git a/tests/userroles/test_add_role_to_user.py b/tests/userroles/test_add_role_to_user.py index f444085f1..e4c266a74 100644 --- a/tests/userroles/test_add_role_to_user.py +++ b/tests/userroles/test_add_role_to_user.py @@ -64,12 +64,12 @@ async def test_add_new_role_to_user(): assert result.created_new_role # Add role to the user - result = await asyncio.add_role_to_user(user_id, role) + result = await asyncio.add_role_to_user("public", user_id, role) assert isinstance(result, interfaces.AddRoleToUserOkResult) assert not result.did_user_already_have_role # Check that now the user has the assigned role - result = await asyncio.get_roles_for_user(user_id) + result = await asyncio.get_roles_for_user("public", user_id) assert isinstance(result, interfaces.GetRolesForUserOkResult) assert result.roles == [role] @@ -105,17 +105,17 @@ async def test_add_duplicate_role_to_user(): assert result.created_new_role # Add role to the user - result = await asyncio.add_role_to_user(user_id, role) + result = await asyncio.add_role_to_user("public", user_id, role) assert isinstance(result, interfaces.AddRoleToUserOkResult) assert not result.did_user_already_have_role # Add role to the user - result = await asyncio.add_role_to_user(user_id, role) + result = await asyncio.add_role_to_user("public", user_id, role) assert isinstance(result, interfaces.AddRoleToUserOkResult) assert result.did_user_already_have_role # Check that now the user has the assigned role - result = await asyncio.get_roles_for_user(user_id) + result = await asyncio.get_roles_for_user("public", user_id) assert isinstance(result, interfaces.GetRolesForUserOkResult) assert result.roles == [role] @@ -146,10 +146,10 @@ async def test_add_unknown_role_to_user(): role = "role" # Add role to the user (without creating the role first) - result = await asyncio.add_role_to_user(user_id, role) + result = await asyncio.add_role_to_user("public", user_id, role) assert isinstance(result, interfaces.UnknownRoleError) # Check that the user doesn't get any role - result = await asyncio.get_roles_for_user(user_id) + result = await asyncio.get_roles_for_user("public", user_id) assert isinstance(result, interfaces.GetRolesForUserOkResult) assert result.roles == [] diff --git a/tests/userroles/test_claims.py b/tests/userroles/test_claims.py index d7f5b1d59..46743bf61 100644 --- a/tests/userroles/test_claims.py +++ b/tests/userroles/test_claims.py @@ -56,7 +56,7 @@ async def test_add_claims_to_session_without_config(): user_id = "userId" req = MagicMock() - s = await create_new_session(req, user_id) + s = await create_new_session("public", req, user_id) assert s.sync_get_claim_value(UserRoleClaim) == [] assert (await s.get_claim_value(PermissionClaim)) == [] @@ -78,7 +78,7 @@ async def test_claims_not_added_to_session_if_disabled(): user_id = "userId" req = MagicMock() - s = await create_new_session(req, user_id) + s = await create_new_session("public", req, user_id) assert (await s.get_claim_value(UserRoleClaim)) is None assert s.sync_get_claim_value(PermissionClaim) is None @@ -99,9 +99,9 @@ async def test_add_claims_to_session_with_values(): req = MagicMock() await create_new_role_or_add_permissions(role, ["a", "b"]) - await add_role_to_user(user_id, role) + await add_role_to_user("public", user_id, role) - s = await create_new_session(req, user_id) + s = await create_new_session("public", req, user_id) assert s.sync_get_claim_value(UserRoleClaim) == [role] value: List[str] = await s.get_claim_value(PermissionClaim) # type: ignore assert sorted(value) == sorted(["a", "b"]) @@ -124,9 +124,9 @@ async def test_should_validate_roles(): req = MagicMock() await create_new_role_or_add_permissions(role, ["a", "b"]) - await add_role_to_user(user_id, role) + await add_role_to_user("public", user_id, role) - s = await create_new_session(req, user_id) + s = await create_new_session("public", req, user_id) await s.assert_claims([UserRoleClaim.validators.includes(role)]) with pytest.raises(Exception) as e: @@ -159,10 +159,10 @@ async def test_should_validate_roles_after_refetch(): role = "role" req = MagicMock() - s = await create_new_session(req, user_id) + s = await create_new_session("public", req, user_id) await create_new_role_or_add_permissions(role, ["a", "b"]) - await add_role_to_user(user_id, role) + await add_role_to_user("public", user_id, role) await s.assert_claims([UserRoleClaim.validators.includes(role)]) @@ -185,9 +185,9 @@ async def test_should_validate_permissions(): req = MagicMock() await create_new_role_or_add_permissions(role, permissions) - await add_role_to_user(user_id, role) + await add_role_to_user("public", user_id, role) - s = await create_new_session(req, user_id) + s = await create_new_session("public", req, user_id) await s.assert_claims([PermissionClaim.validators.includes("a")]) with pytest.raises(Exception) as e: @@ -223,9 +223,9 @@ async def test_should_validate_permissions_after_refetch(): permissions = ["a", "b"] req = MagicMock() - s = await create_new_session(req, user_id) + s = await create_new_session("public", req, user_id) await create_new_role_or_add_permissions(role, permissions) - await add_role_to_user(user_id, role) + await add_role_to_user("public", user_id, role) await s.assert_claims([PermissionClaim.validators.includes("a")]) diff --git a/tests/userroles/test_delete_role.py b/tests/userroles/test_delete_role.py index f201be74b..d8152054b 100644 --- a/tests/userroles/test_delete_role.py +++ b/tests/userroles/test_delete_role.py @@ -64,7 +64,7 @@ async def test_create_and_assign_new_role_and_delete_it(): assert isinstance(result, interfaces.CreateNewRoleOrAddPermissionsOkResult) assert result.created_new_role - result = await asyncio.add_role_to_user(user_id, role) + result = await asyncio.add_role_to_user("public", user_id, role) assert isinstance(result, interfaces.AddRoleToUserOkResult) assert not result.did_user_already_have_role @@ -78,7 +78,7 @@ async def test_create_and_assign_new_role_and_delete_it(): assert isinstance(result, interfaces.GetAllRolesOkResult) assert roles[1] not in result.roles - result = await asyncio.get_roles_for_user(user_id) + result = await asyncio.get_roles_for_user("public", user_id) assert isinstance(result, interfaces.GetRolesForUserOkResult) assert roles[1] not in result.roles diff --git a/tests/userroles/test_get_roles_for_user.py b/tests/userroles/test_get_roles_for_user.py index a3575b94d..1e82ebfe0 100644 --- a/tests/userroles/test_get_roles_for_user.py +++ b/tests/userroles/test_get_roles_for_user.py @@ -64,11 +64,11 @@ async def test_get_roles_for_user(): assert isinstance(result, interfaces.CreateNewRoleOrAddPermissionsOkResult) assert result.created_new_role - result = await asyncio.add_role_to_user(user_id, role) + result = await asyncio.add_role_to_user("public", user_id, role) assert isinstance(result, interfaces.AddRoleToUserOkResult) assert not result.did_user_already_have_role # Get all the roles assigned the user - result = await asyncio.get_roles_for_user(user_id) + result = await asyncio.get_roles_for_user("public", user_id) assert isinstance(result, interfaces.GetRolesForUserOkResult) assert result.roles == roles diff --git a/tests/userroles/test_get_users_that_have_role.py b/tests/userroles/test_get_users_that_have_role.py index e7b2d2625..4be310a48 100644 --- a/tests/userroles/test_get_users_that_have_role.py +++ b/tests/userroles/test_get_users_that_have_role.py @@ -65,12 +65,12 @@ async def test_get_users_that_have_role(): # Assign the role to users: for user in users: - result = await asyncio.add_role_to_user(user, role) + result = await asyncio.add_role_to_user("public", user, role) assert isinstance(result, interfaces.AddRoleToUserOkResult) assert not result.did_user_already_have_role # Get all users for a certain role - result = await asyncio.get_users_that_have_role(role) + result = await asyncio.get_users_that_have_role("public", role) assert isinstance(result, interfaces.GetUsersThatHaveRoleOkResult) assert result.users == users @@ -100,5 +100,5 @@ async def test_get_users_for_unknown_role(): role = "role" # Get all users for a certain role - result = await asyncio.get_users_that_have_role(role) + result = await asyncio.get_users_that_have_role("public", role) assert isinstance(result, interfaces.UnknownRoleError) diff --git a/tests/userroles/test_multitenancy.py b/tests/userroles/test_multitenancy.py index 33ebc9359..54017f1ff 100644 --- a/tests/userroles/test_multitenancy.py +++ b/tests/userroles/test_multitenancy.py @@ -60,7 +60,7 @@ async def test_multitenancy_in_user_roles(): await create_or_update_tenant("t2", TenantConfig(email_password_enabled=True)) await create_or_update_tenant("t3", TenantConfig(email_password_enabled=True)) - user = await sign_up("test@example.com", "password1") + user = await sign_up("public", "test@example.com", "password1") assert isinstance(user, SignUpOkResult) user_id = user.user.user_id @@ -72,18 +72,18 @@ async def test_multitenancy_in_user_roles(): await create_new_role_or_add_permissions("role2", []) await create_new_role_or_add_permissions("role3", []) - await add_role_to_user(user_id, "role1", "t1") - await add_role_to_user(user_id, "role2", "t1") - await add_role_to_user(user_id, "role2", "t2") - await add_role_to_user(user_id, "role3", "t2") - await add_role_to_user(user_id, "role3", "t3") - await add_role_to_user(user_id, "role1", "t3") + await add_role_to_user("t1", user_id, "role1") + await add_role_to_user("t1", user_id, "role2") + await add_role_to_user("t2", user_id, "role2") + await add_role_to_user("t2", user_id, "role3") + await add_role_to_user("t3", user_id, "role3") + await add_role_to_user("t3", user_id, "role1") - roles = await get_roles_for_user(user_id, "t1") + roles = await get_roles_for_user("t1", user_id) assert roles.roles == ["role1", "role2"] - roles = await get_roles_for_user(user_id, "t2") + roles = await get_roles_for_user("t2", user_id) assert roles.roles == ["role2", "role3"] - roles = await get_roles_for_user(user_id, "t3") + roles = await get_roles_for_user("t3", user_id) assert roles.roles == ["role1", "role3"] diff --git a/tests/userroles/test_remove_permissions_from_role.py b/tests/userroles/test_remove_permissions_from_role.py index 422887268..060464cfc 100644 --- a/tests/userroles/test_remove_permissions_from_role.py +++ b/tests/userroles/test_remove_permissions_from_role.py @@ -98,5 +98,5 @@ async def test_remove_permissions_from_unknown_role(): role = "role" # Get all users for a certain role - result = await asyncio.get_users_that_have_role(role) + result = await asyncio.get_users_that_have_role("public", role) assert isinstance(result, interfaces.UnknownRoleError) diff --git a/tests/userroles/test_remove_user_role.py b/tests/userroles/test_remove_user_role.py index 09add970f..93f414a65 100644 --- a/tests/userroles/test_remove_user_role.py +++ b/tests/userroles/test_remove_user_role.py @@ -64,22 +64,22 @@ async def test_remove_role_from_a_user(): assert result.created_new_role # Add role to the user: - result = await asyncio.add_role_to_user(user_id, role) + result = await asyncio.add_role_to_user("public", user_id, role) assert isinstance(result, interfaces.AddRoleToUserOkResult) assert not result.did_user_already_have_role # Check that user has a role: - result = await asyncio.get_roles_for_user(user_id) + result = await asyncio.get_roles_for_user("public", user_id) assert isinstance(result, interfaces.GetRolesForUserOkResult) assert result.roles == [role] # Remove role from the user: - result = await asyncio.remove_user_role(user_id, role) + result = await asyncio.remove_user_role("public", user_id, role) assert isinstance(result, interfaces.RemoveUserRoleOkResult) assert result.did_user_have_role # Check that the permission has been removed from the role: - result = await asyncio.get_roles_for_user(user_id) + result = await asyncio.get_roles_for_user("public", user_id) assert isinstance(result, interfaces.GetRolesForUserOkResult) assert result.roles == [] @@ -115,7 +115,7 @@ async def test_remove_unassigned_role_from_user(): assert result.created_new_role # Remove (unassigned) role from the user: - result = await asyncio.remove_user_role(user_id, role) + result = await asyncio.remove_user_role("public", user_id, role) assert isinstance(result, interfaces.RemoveUserRoleOkResult) assert not result.did_user_have_role @@ -146,5 +146,5 @@ async def test_remove_non_existent_role_from_user(): role = "role" # Remove (non-existent) role from the user: - result = await asyncio.remove_user_role(user_id, role) + result = await asyncio.remove_user_role("public", user_id, role) assert isinstance(result, interfaces.UnknownRoleError) diff --git a/tests/utils.py b/tests/utils.py index 74a51c85f..0acd3fd69 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -584,23 +584,25 @@ async def create_users( users = json.loads(json_data.read())["users"] for user in users: if user["recipe"] == "emailpassword" and emailpassword: - await sign_up(user["email"], user["password"]) + await sign_up("public", user["email"], user["password"]) elif user["recipe"] == "passwordless" and passwordless: if user.get("email"): - coderesponse = await create_code(user["email"]) + coderesponse = await create_code("public", user["email"]) await consume_code( + "public", coderesponse.pre_auth_session_id, coderesponse.user_input_code, coderesponse.device_id, ) else: - coderesponse = await create_code(None, user["phone"]) + coderesponse = await create_code("public", None, user["phone"]) await consume_code( + "public", coderesponse.pre_auth_session_id, coderesponse.user_input_code, coderesponse.device_id, ) elif user["recipe"] == "thirdparty" and thirdparty: await manually_create_or_update_user( - user["provider"], user["userId"], user["email"] + "public", user["provider"], user["userId"], user["email"] ) From 5e08c6dce015313f240223712ee3a060549a13c5 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Fri, 11 Aug 2023 11:53:16 +0530 Subject: [PATCH 2/3] fixes review comments --- .../recipe/session/asyncio/__init__.py | 2 +- .../recipe/session/syncio/__init__.py | 2 +- .../recipe/thirdparty/api/implementation.py | 1 - .../thirdpartyemailpassword/asyncio/__init__.py | 3 ++- supertokens_python/syncio/__init__.py | 15 +++++++++++---- tests/Django/test_django.py | 15 ++++++++++----- tests/Fastapi/test_fastapi.py | 6 +++--- tests/Flask/test_flask.py | 17 +++++++++++------ tests/emailpassword/test_emailexists.py | 2 +- tests/emailpassword/test_emailverify.py | 2 +- tests/emailpassword/test_passwordreset.py | 2 +- tests/emailpassword/test_signin.py | 2 +- .../frontendIntegration/django2x/polls/views.py | 2 +- .../frontendIntegration/django3x/polls/views.py | 2 +- tests/frontendIntegration/fastapi-server/app.py | 2 +- tests/frontendIntegration/flask-server/app.py | 2 +- tests/jwt/test_get_JWKS.py | 2 +- tests/sessions/claims/test_verify_session.py | 4 ++-- tests/sessions/test_access_token_v3.py | 2 +- tests/sessions/test_auth_mode.py | 2 +- tests/test_session.py | 2 +- tests/thirdparty/test_thirdparty.py | 13 +++++++++---- 22 files changed, 62 insertions(+), 40 deletions(-) diff --git a/supertokens_python/recipe/session/asyncio/__init__.py b/supertokens_python/recipe/session/asyncio/__init__.py index 3e8ae4871..a1a8a9579 100644 --- a/supertokens_python/recipe/session/asyncio/__init__.py +++ b/supertokens_python/recipe/session/asyncio/__init__.py @@ -49,8 +49,8 @@ async def create_new_session( - tenant_id: str, request: Any, + tenant_id: str, user_id: str, access_token_payload: Union[Dict[str, Any], None] = None, session_data_in_database: Union[Dict[str, Any], None] = None, diff --git a/supertokens_python/recipe/session/syncio/__init__.py b/supertokens_python/recipe/session/syncio/__init__.py index 3a7557d6e..d398c7fb6 100644 --- a/supertokens_python/recipe/session/syncio/__init__.py +++ b/supertokens_python/recipe/session/syncio/__init__.py @@ -39,8 +39,8 @@ def create_new_session( - tenant_id: str, request: Any, + tenant_id: str, user_id: str, access_token_payload: Union[Dict[str, Any], None] = None, session_data_in_database: Union[Dict[str, Any], None] = None, diff --git a/supertokens_python/recipe/thirdparty/api/implementation.py b/supertokens_python/recipe/thirdparty/api/implementation.py index 7135067ce..4caec19b0 100644 --- a/supertokens_python/recipe/thirdparty/api/implementation.py +++ b/supertokens_python/recipe/thirdparty/api/implementation.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. from __future__ import annotations -from supertokens_python.utils import utf_base64decode from base64 import b64decode import json diff --git a/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py b/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py index b6aeb4a78..db1dcdf2e 100644 --- a/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py +++ b/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py @@ -26,7 +26,7 @@ CreateResetPasswordLinkUknownUserIdError, CreateResetPasswordLinkOkResult, SendResetPasswordEmailUnknownUserIdError, - SendResetPasswordEmailEmailOkResult + SendResetPasswordEmailEmailOkResult, ) from supertokens_python.recipe.emailpassword.utils import get_password_reset_link @@ -61,6 +61,7 @@ async def get_user_by_third_party_info( user_context, ) + async def thirdparty_manually_create_or_update_user( tenant_id: str, third_party_id: str, diff --git a/supertokens_python/syncio/__init__.py b/supertokens_python/syncio/__init__.py index 874a8a35c..06980dfab 100644 --- a/supertokens_python/syncio/__init__.py +++ b/supertokens_python/syncio/__init__.py @@ -29,6 +29,7 @@ def get_users_oldest_first( + tenant_id: str, limit: Union[int, None] = None, pagination_token: Union[str, None] = None, include_recipe_ids: Union[None, List[str]] = None, @@ -36,12 +37,13 @@ def get_users_oldest_first( ) -> UsersResponse: return sync( Supertokens.get_instance().get_users( - "public", "ASC", limit, pagination_token, include_recipe_ids, query + tenant_id, "ASC", limit, pagination_token, include_recipe_ids, query ) ) def get_users_newest_first( + tenant_id: str, limit: Union[int, None] = None, pagination_token: Union[str, None] = None, include_recipe_ids: Union[None, List[str]] = None, @@ -49,13 +51,18 @@ def get_users_newest_first( ) -> UsersResponse: return sync( Supertokens.get_instance().get_users( - "public", "DESC", limit, pagination_token, include_recipe_ids, query + tenant_id, "DESC", limit, pagination_token, include_recipe_ids, query ) ) -def get_user_count(include_recipe_ids: Union[None, List[str]] = None) -> int: - return sync(Supertokens.get_instance().get_user_count(include_recipe_ids)) +def get_user_count( + include_recipe_ids: Union[None, List[str]] = None, + tenant_id: Optional[str] = None, +) -> int: + return sync( + Supertokens.get_instance().get_user_count(include_recipe_ids, tenant_id) + ) def delete_user(user_id: str) -> None: diff --git a/tests/Django/test_django.py b/tests/Django/test_django.py index c22a2b1f2..67662161a 100644 --- a/tests/Django/test_django.py +++ b/tests/Django/test_django.py @@ -76,7 +76,7 @@ def get_cookies(response: HttpResponse) -> Dict[str, Any]: async def create_new_session_view(request: HttpRequest): - await create_new_session("public", request, "user_id") + await create_new_session(request, "public", "user_id") return JsonResponse({"foo": "bar"}) @@ -456,10 +456,12 @@ async def test_thirdparty_parsing_works(self): start_st() - state = b64encode(json.dumps({"redirectURI": "http://localhost:3000/redirect" }).encode()).decode() + state = b64encode( + json.dumps({"redirectURI": "http://localhost:3000/redirect"}).encode() + ).decode() code = "testing" - data = { "state": state, "code": code} + data = {"state": state, "code": code} request = self.factory.post( "/auth/callback/apple", @@ -472,8 +474,11 @@ async def test_thirdparty_parsing_works(self): response = await temp self.assertEqual(response.status_code, 303) - self.assertEqual(response.content, b'') - self.assertEqual(response.headers['location'], f"http://localhost:3000/redirect?state={state.replace('=', '%3D')}&code={code}") + self.assertEqual(response.content, b"") + self.assertEqual( + response.headers["location"], + f"http://localhost:3000/redirect?state={state.replace('=', '%3D')}&code={code}", + ) @pytest.mark.asyncio async def test_search_with_multiple_emails(self): diff --git a/tests/Fastapi/test_fastapi.py b/tests/Fastapi/test_fastapi.py index d56287afe..4491e8889 100644 --- a/tests/Fastapi/test_fastapi.py +++ b/tests/Fastapi/test_fastapi.py @@ -91,7 +91,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session("public", request, user_id, {}, {}) + await create_new_session(request, "public", user_id, {}, {}) return {"userId": user_id} @app.post("/refresh") @@ -135,12 +135,12 @@ async def custom_logout(request: Request): # type: ignore @app.post("/create") async def _create(request: Request): # type: ignore - await create_new_session("public", request, "userId", {}, {}) + await create_new_session(request, "public", "userId", {}, {}) return "" @app.post("/create-throw") async def _create_throw(request: Request): # type: ignore - await create_new_session("public", request, "userId", {}, {}) + await create_new_session(request, "public", "userId", {}, {}) raise UnauthorisedError("unauthorised") return TestClient(app) diff --git a/tests/Flask/test_flask.py b/tests/Flask/test_flask.py index 03964c96a..fd08b4162 100644 --- a/tests/Flask/test_flask.py +++ b/tests/Flask/test_flask.py @@ -192,7 +192,7 @@ def t(): # type: ignore @app.route("/login") # type: ignore def login(): # type: ignore user_id = "userId" - create_new_session("public", request, user_id, {}, {}) + create_new_session(request, "public", user_id, {}, {}) return jsonify({"userId": user_id, "session": "ssss"}) @@ -478,15 +478,20 @@ def test_thirdparty_parsing_works(driver_config_app: Any): start_st() test_client = driver_config_app.test_client() - state = b64encode(json.dumps({"redirectURI": "http://localhost:3000/redirect" }).encode()).decode() + state = b64encode( + json.dumps({"redirectURI": "http://localhost:3000/redirect"}).encode() + ).decode() code = "testing" - data = { "state": state, "code": code} + data = {"state": state, "code": code} res = test_client.post("/auth/callback/apple", data=data) assert res.status_code == 303 - assert res.data == b'' - assert res.headers["location"] == f"http://localhost:3000/redirect?state={state.replace('=', '%3D')}&code={code}" + assert res.data == b"" + assert ( + res.headers["location"] + == f"http://localhost:3000/redirect?state={state.replace('=', '%3D')}&code={code}" + ) from flask.wrappers import Response @@ -747,7 +752,7 @@ def test_api(): # type: ignore @app.route("/login") # type: ignore def login(): # type: ignore user_id = "userId" - s = create_new_session("public", request, user_id, {}, {}) + s = create_new_session(request, "public", user_id, {}, {}) return jsonify({"user": s.get_user_id()}) @app.route("/ping") # type: ignore diff --git a/tests/emailpassword/test_emailexists.py b/tests/emailpassword/test_emailexists.py index 5f9caec03..f5bbd10a7 100644 --- a/tests/emailpassword/test_emailexists.py +++ b/tests/emailpassword/test_emailexists.py @@ -50,7 +50,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session("public", request, user_id, {}, {}) + await create_new_session(request, "public", user_id, {}, {}) return {"userId": user_id} @app.post("/refresh") diff --git a/tests/emailpassword/test_emailverify.py b/tests/emailpassword/test_emailverify.py index 03fc8cb43..c966c6bfc 100644 --- a/tests/emailpassword/test_emailverify.py +++ b/tests/emailpassword/test_emailverify.py @@ -79,7 +79,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session("public", request, user_id, {}, {}) + await create_new_session(request, "public", user_id, {}, {}) return {"userId": user_id} @app.post("/refresh") diff --git a/tests/emailpassword/test_passwordreset.py b/tests/emailpassword/test_passwordreset.py index 3fd4d3615..6a67dc632 100644 --- a/tests/emailpassword/test_passwordreset.py +++ b/tests/emailpassword/test_passwordreset.py @@ -50,7 +50,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session("public", request, user_id, {}, {}) + await create_new_session(request, "public", user_id, {}, {}) return {"userId": user_id} @app.post("/refresh") diff --git a/tests/emailpassword/test_signin.py b/tests/emailpassword/test_signin.py index 5206318d9..dad3d2ca9 100644 --- a/tests/emailpassword/test_signin.py +++ b/tests/emailpassword/test_signin.py @@ -60,7 +60,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session("public", request, user_id, {}, {}) + await create_new_session(request, "public", user_id, {}, {}) return {"userId": user_id} @app.post("/refresh") diff --git a/tests/frontendIntegration/django2x/polls/views.py b/tests/frontendIntegration/django2x/polls/views.py index 0c1ecd230..d2980294c 100644 --- a/tests/frontendIntegration/django2x/polls/views.py +++ b/tests/frontendIntegration/django2x/polls/views.py @@ -396,7 +396,7 @@ def login(request: HttpRequest): if request.method == "POST": user_id = json.loads(request.body)["userId"] - session_ = create_new_session("public", request, user_id) + session_ = create_new_session(request, "public", user_id) return HttpResponse(session_.get_user_id()) else: return send_options_api_response() diff --git a/tests/frontendIntegration/django3x/polls/views.py b/tests/frontendIntegration/django3x/polls/views.py index d61f5842b..5eba8f81f 100644 --- a/tests/frontendIntegration/django3x/polls/views.py +++ b/tests/frontendIntegration/django3x/polls/views.py @@ -400,7 +400,7 @@ async def login(request: HttpRequest): if request.method == "POST": user_id = json.loads(request.body)["userId"] - session_ = await create_new_session("public", request, user_id) + session_ = await create_new_session(request, "public", user_id) return HttpResponse(session_.get_user_id()) else: return send_options_api_response() diff --git a/tests/frontendIntegration/fastapi-server/app.py b/tests/frontendIntegration/fastapi-server/app.py index 1dfd11f2d..c1af0c2db 100644 --- a/tests/frontendIntegration/fastapi-server/app.py +++ b/tests/frontendIntegration/fastapi-server/app.py @@ -265,7 +265,7 @@ def login_options(): @app.post("/login") async def login(request: Request): user_id = (await request.json())["userId"] - _session = await create_new_session("public", request, user_id) + _session = await create_new_session(request, "public", user_id) return PlainTextResponse(content=_session.get_user_id()) diff --git a/tests/frontendIntegration/flask-server/app.py b/tests/frontendIntegration/flask-server/app.py index 6edc21cfc..8e6ec9f33 100644 --- a/tests/frontendIntegration/flask-server/app.py +++ b/tests/frontendIntegration/flask-server/app.py @@ -287,7 +287,7 @@ def login_options(): @app.route("/login", methods=["POST"]) # type: ignore def login(): user_id: str = request.get_json()["userId"] # type: ignore - _session = create_new_session("public", request, user_id) + _session = create_new_session(request, "public", user_id) return _session.get_user_id() diff --git a/tests/jwt/test_get_JWKS.py b/tests/jwt/test_get_JWKS.py index 91e4d7c4b..665c24d36 100644 --- a/tests/jwt/test_get_JWKS.py +++ b/tests/jwt/test_get_JWKS.py @@ -49,7 +49,7 @@ async def driver_config_client(): @app.get("/login") async def login(request: Request): # type: ignore user_id = "userId" - await create_new_session("public", request, user_id, {}, {}) + await create_new_session(request, "public", user_id, {}, {}) return {"userId": user_id} return TestClient(app) diff --git a/tests/sessions/claims/test_verify_session.py b/tests/sessions/claims/test_verify_session.py index fe5bb5d83..4f8d3c2ed 100644 --- a/tests/sessions/claims/test_verify_session.py +++ b/tests/sessions/claims/test_verify_session.py @@ -134,13 +134,13 @@ async def fastapi_client(): @app.post("/login") async def _login(request: Request): # type: ignore user_id = "userId" - await create_new_session("public", request, user_id, {}, {}) + await create_new_session(request, "public", user_id, {}, {}) return {"userId": user_id} @app.post("/create-with-claim") async def _create_with_claim(request: Request): # type: ignore user_id = "userId" - _ = await create_new_session("public", request, user_id, {}, {}) + _ = await create_new_session(request, "public", user_id, {}, {}) key: str = (await request.json())["key"] # PrimitiveClaim(key, fetch_value="Value").add_to_session(session, "value") return {"userId": key} diff --git a/tests/sessions/test_access_token_v3.py b/tests/sessions/test_access_token_v3.py index dd9e72265..64c99a235 100644 --- a/tests/sessions/test_access_token_v3.py +++ b/tests/sessions/test_access_token_v3.py @@ -74,7 +74,7 @@ async def _create(request: Request): # type: ignore except Exception: pass - session = await create_new_session("public", request, "userId", body, {}) + session = await create_new_session(request, "public", "userId", body, {}) return {"message": True, "sessionHandle": session.get_handle()} @fast.get("/merge-into-payload") diff --git a/tests/sessions/test_auth_mode.py b/tests/sessions/test_auth_mode.py index d38f215ab..a7babf5fd 100644 --- a/tests/sessions/test_auth_mode.py +++ b/tests/sessions/test_auth_mode.py @@ -33,7 +33,7 @@ async def app(): @fast.post("/create") async def _create(request: Request): # type: ignore body = await request.json() - session = await create_new_session("public", request, "userId", body, {}) + session = await create_new_session(request, "public", "userId", body, {}) return {"message": True, "sessionHandle": session.get_handle()} @fast.get("/update-payload") diff --git a/tests/test_session.py b/tests/test_session.py index 35a691248..900529222 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -258,7 +258,7 @@ async def home(_request: Request): # type: ignore @app.post("/create") async def create_api(request: Request): # type: ignore - await async_create_new_session("public", request, "test-user", {}, {}) + await async_create_new_session(request, "public", "test-user", {}, {}) return "" return TestClient(app) diff --git a/tests/thirdparty/test_thirdparty.py b/tests/thirdparty/test_thirdparty.py index 7e8584e25..81ba6c1cc 100644 --- a/tests/thirdparty/test_thirdparty.py +++ b/tests/thirdparty/test_thirdparty.py @@ -67,12 +67,17 @@ async def test_thirdpary_parsing_works(fastapi_client: TestClient): init(**st_init_args) # type: ignore start_st() - state = b64encode(json.dumps({"redirectURI": "http://localhost:3000/redirect" }).encode()).decode() + state = b64encode( + json.dumps({"redirectURI": "http://localhost:3000/redirect"}).encode() + ).decode() code = "testing" - data = { "state": state, "code": code} + data = {"state": state, "code": code} res = fastapi_client.post("/auth/callback/apple", data=data) assert res.status_code == 303 - assert res.content == b'' - assert res.headers["location"] == f"http://localhost:3000/redirect?state={state.replace('=', '%3D')}&code={code}" + assert res.content == b"" + assert ( + res.headers["location"] + == f"http://localhost:3000/redirect?state={state.replace('=', '%3D')}&code={code}" + ) From 91198a02a559968ce8066bdd1681743e61f9c2f5 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Fri, 11 Aug 2023 11:57:01 +0530 Subject: [PATCH 3/3] fixes review comments --- .../recipe/emailpassword/asyncio/__init__.py | 12 +++---- .../emailverification/asyncio/__init__.py | 10 +++--- .../multitenancy/recipe_implementation.py | 19 +++-------- .../recipe/session/asyncio/__init__.py | 4 +-- .../recipe/session/session_functions.py | 3 +- .../recipe/thirdparty/asyncio/__init__.py | 4 +-- .../asyncio/__init__.py | 20 ++++++------ .../asyncio/__init__.py | 32 +++++++++---------- .../recipe/userroles/asyncio/__init__.py | 9 +++--- .../recipe/userroles/recipe_implementation.py | 11 +++---- supertokens_python/recipe_module.py | 2 +- 11 files changed, 52 insertions(+), 74 deletions(-) diff --git a/supertokens_python/recipe/emailpassword/asyncio/__init__.py b/supertokens_python/recipe/emailpassword/asyncio/__init__.py index 68677f34c..292799eed 100644 --- a/supertokens_python/recipe/emailpassword/asyncio/__init__.py +++ b/supertokens_python/recipe/emailpassword/asyncio/__init__.py @@ -70,7 +70,7 @@ async def get_user_by_email( if user_context is None: user_context = {} return await EmailPasswordRecipe.get_instance().recipe_implementation.get_user_by_email( - tenant_id or DEFAULT_TENANT_ID, email, user_context + tenant_id, email, user_context ) @@ -80,7 +80,7 @@ async def create_reset_password_token( if user_context is None: user_context = {} return await EmailPasswordRecipe.get_instance().recipe_implementation.create_reset_password_token( - user_id, tenant_id or DEFAULT_TENANT_ID, user_context + user_id, tenant_id, user_context ) @@ -93,7 +93,7 @@ async def reset_password_using_token( if user_context is None: user_context = {} return await EmailPasswordRecipe.get_instance().recipe_implementation.reset_password_using_token( - new_password, tenant_id or DEFAULT_TENANT_ID, token, user_context + new_password, tenant_id, token, user_context ) @@ -106,7 +106,7 @@ async def sign_in( if user_context is None: user_context = {} return await EmailPasswordRecipe.get_instance().recipe_implementation.sign_in( - email, password, tenant_id or DEFAULT_TENANT_ID, user_context + email, password, tenant_id, user_context ) @@ -119,7 +119,7 @@ async def sign_up( if user_context is None: user_context = {} return await EmailPasswordRecipe.get_instance().recipe_implementation.sign_up( - email, password, tenant_id or DEFAULT_TENANT_ID, user_context + email, password, tenant_id, user_context ) @@ -147,7 +147,7 @@ async def create_reset_password_link( recipe_instance.get_app_info(), recipe_instance.get_recipe_id(), token.token, - tenant_id or DEFAULT_TENANT_ID, + tenant_id, ) ) diff --git a/supertokens_python/recipe/emailverification/asyncio/__init__.py b/supertokens_python/recipe/emailverification/asyncio/__init__.py index abb6fdae9..9fe1888a3 100644 --- a/supertokens_python/recipe/emailverification/asyncio/__init__.py +++ b/supertokens_python/recipe/emailverification/asyncio/__init__.py @@ -27,8 +27,6 @@ from supertokens_python.recipe.emailverification.types import EmailTemplateVars from supertokens_python.recipe.emailverification.recipe import EmailVerificationRecipe -from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID - from supertokens_python.recipe.emailverification.utils import get_email_verify_link from supertokens_python.recipe.emailverification.types import ( VerificationEmailTemplateVars, @@ -58,7 +56,7 @@ async def create_email_verification_token( raise Exception("Unknown User ID provided without email") return await recipe.recipe_implementation.create_email_verification_token( - user_id, email, tenant_id or DEFAULT_TENANT_ID, user_context + user_id, email, tenant_id, user_context ) @@ -68,7 +66,7 @@ async def verify_email_using_token( if user_context is None: user_context = {} return await EmailVerificationRecipe.get_instance().recipe_implementation.verify_email_using_token( - token, tenant_id or DEFAULT_TENANT_ID, user_context + token, tenant_id, user_context ) @@ -115,7 +113,7 @@ async def revoke_email_verification_tokens( raise Exception("Unknown User ID provided without email") return await EmailVerificationRecipe.get_instance().recipe_implementation.revoke_email_verification_tokens( - user_id, email, tenant_id or DEFAULT_TENANT_ID, user_context + user_id, email, tenant_id, user_context ) @@ -183,7 +181,7 @@ async def create_email_verification_link( app_info, email_verification_token.token, recipe_instance.get_recipe_id(), - tenant_id or DEFAULT_TENANT_ID, + tenant_id, ) ) diff --git a/supertokens_python/recipe/multitenancy/recipe_implementation.py b/supertokens_python/recipe/multitenancy/recipe_implementation.py index 195f96e85..6a847b4ce 100644 --- a/supertokens_python/recipe/multitenancy/recipe_implementation.py +++ b/supertokens_python/recipe/multitenancy/recipe_implementation.py @@ -45,7 +45,6 @@ from .utils import MultitenancyConfig from supertokens_python.querier import NormalisedURLPath -from .constants import DEFAULT_TENANT_ID def parse_tenant_config(tenant: Dict[str, Any]) -> TenantConfigResponse: @@ -162,9 +161,7 @@ async def get_tenant( self, tenant_id: Optional[str], user_context: Dict[str, Any] ) -> GetTenantOkResult: res = await self.querier.send_get_request( - NormalisedURLPath( - f"{tenant_id or DEFAULT_TENANT_ID}/recipe/multitenancy/tenant" - ), + NormalisedURLPath(f"{tenant_id}/recipe/multitenancy/tenant"), ) tenant_config = parse_tenant_config(res) @@ -209,9 +206,7 @@ async def create_or_update_third_party_config( user_context: Dict[str, Any], ) -> CreateOrUpdateThirdPartyConfigOkResult: response = await self.querier.send_put_request( - NormalisedURLPath( - f"{tenant_id or DEFAULT_TENANT_ID}/recipe/multitenancy/config/thirdparty" - ), + NormalisedURLPath(f"{tenant_id}/recipe/multitenancy/config/thirdparty"), { "config": config.to_json(), "skipValidation": skip_validation is True, @@ -230,7 +225,7 @@ async def delete_third_party_config( ) -> DeleteThirdPartyConfigOkResult: response = await self.querier.send_post_request( NormalisedURLPath( - f"{tenant_id or DEFAULT_TENANT_ID}/recipe/multitenancy/config/thirdparty/remove" + f"{tenant_id}/recipe/multitenancy/config/thirdparty/remove" ), { "thirdPartyId": third_party_id, @@ -251,9 +246,7 @@ async def associate_user_to_tenant( AssociateUserToTenantThirdPartyUserAlreadyExistsError, ]: response: Dict[str, Any] = await self.querier.send_post_request( - NormalisedURLPath( - f"{tenant_id or DEFAULT_TENANT_ID}/recipe/multitenancy/tenant/user" - ), + NormalisedURLPath(f"{tenant_id}/recipe/multitenancy/tenant/user"), { "userId": user_id, }, @@ -284,9 +277,7 @@ async def dissociate_user_from_tenant( self, tenant_id: str | None, user_id: str, user_context: Dict[str, Any] ) -> DisassociateUserFromTenantOkResult: response = await self.querier.send_post_request( - NormalisedURLPath( - f"{tenant_id or DEFAULT_TENANT_ID}/recipe/multitenancy/tenant/user/remove" - ), + NormalisedURLPath(f"{tenant_id}/recipe/multitenancy/tenant/user/remove"), { "userId": user_id, }, diff --git a/supertokens_python/recipe/session/asyncio/__init__.py b/supertokens_python/recipe/session/asyncio/__init__.py index a1a8a9579..a4878d915 100644 --- a/supertokens_python/recipe/session/asyncio/__init__.py +++ b/supertokens_python/recipe/session/asyncio/__init__.py @@ -107,9 +107,7 @@ async def create_new_session_without_request_response( final_access_token_payload = {**access_token_payload, "iss": issuer} for claim in claims_added_by_other_recipes: - update = await claim.build( - user_id, tenant_id or DEFAULT_TENANT_ID, user_context - ) + update = await claim.build(user_id, tenant_id, user_context) final_access_token_payload = {**final_access_token_payload, **update} return await SessionRecipe.get_instance().recipe_implementation.create_new_session( diff --git a/supertokens_python/recipe/session/session_functions.py b/supertokens_python/recipe/session/session_functions.py index 0e391fc86..3ae16bed3 100644 --- a/supertokens_python/recipe/session/session_functions.py +++ b/supertokens_python/recipe/session/session_functions.py @@ -300,8 +300,7 @@ async def get_session( ] # if the token didn't pass validation, but we got here, it means it was a v2 token that we didn't have the key cached for. ), # This will throw error if others are none and 'expiryTime' key doesn't exist in the payload response["session"].get("tenantId") - or (access_token_info or {}).get("tenantId") - or DEFAULT_TENANT_ID, + or (access_token_info or {}).get("tenantId"), ), GetSessionAPIResponseAccessToken( response["accessToken"]["token"], diff --git a/supertokens_python/recipe/thirdparty/asyncio/__init__.py b/supertokens_python/recipe/thirdparty/asyncio/__init__.py index a216461dc..0e70c5166 100644 --- a/supertokens_python/recipe/thirdparty/asyncio/__init__.py +++ b/supertokens_python/recipe/thirdparty/asyncio/__init__.py @@ -18,8 +18,6 @@ from ..types import User -from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID - async def get_user_by_id( user_id: str, user_context: Union[None, Dict[str, Any]] = None @@ -38,7 +36,7 @@ async def get_users_by_email( user_context = {} return ( await ThirdPartyRecipe.get_instance().recipe_implementation.get_users_by_email( - email, tenant_id or DEFAULT_TENANT_ID, user_context + email, tenant_id, user_context ) ) diff --git a/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py b/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py index db1dcdf2e..aeba3cd30 100644 --- a/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py +++ b/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py @@ -57,7 +57,7 @@ async def get_user_by_third_party_info( return await ThirdPartyEmailPasswordRecipe.get_instance().recipe_implementation.get_user_by_thirdparty_info( third_party_id, third_party_user_id, - tenant_id or DEFAULT_TENANT_ID, + tenant_id, user_context, ) @@ -75,7 +75,7 @@ async def thirdparty_manually_create_or_update_user( third_party_id, third_party_user_id, email, - tenant_id or DEFAULT_TENANT_ID, + tenant_id, user_context, ) @@ -89,7 +89,7 @@ async def thirdparty_get_provider( if user_context is None: user_context = {} return await ThirdPartyEmailPasswordRecipe.get_instance().recipe_implementation.thirdparty_get_provider( - third_party_id, client_type, tenant_id or DEFAULT_TENANT_ID, user_context + third_party_id, client_type, tenant_id, user_context ) @@ -99,7 +99,7 @@ async def create_reset_password_token( if user_context is None: user_context = {} return await ThirdPartyEmailPasswordRecipe.get_instance().recipe_implementation.create_reset_password_token( - user_id, tenant_id or DEFAULT_TENANT_ID, user_context + user_id, tenant_id, user_context ) @@ -112,7 +112,7 @@ async def reset_password_using_token( if user_context is None: user_context = {} return await ThirdPartyEmailPasswordRecipe.get_instance().recipe_implementation.reset_password_using_token( - token, new_password, tenant_id or DEFAULT_TENANT_ID, user_context + token, new_password, tenant_id, user_context ) @@ -125,7 +125,7 @@ async def emailpassword_sign_in( if user_context is None: user_context = {} return await ThirdPartyEmailPasswordRecipe.get_instance().recipe_implementation.emailpassword_sign_in( - email, password, tenant_id or DEFAULT_TENANT_ID, user_context + email, password, tenant_id, user_context ) @@ -138,7 +138,7 @@ async def emailpassword_sign_up( if user_context is None: user_context = {} return await ThirdPartyEmailPasswordRecipe.get_instance().recipe_implementation.emailpassword_sign_up( - email, password, tenant_id or DEFAULT_TENANT_ID, user_context + email, password, tenant_id, user_context ) @@ -168,7 +168,7 @@ async def get_users_by_email( if user_context is None: user_context = {} return await ThirdPartyEmailPasswordRecipe.get_instance().recipe_implementation.get_users_by_email( - email, tenant_id or DEFAULT_TENANT_ID, user_context + email, tenant_id, user_context ) @@ -178,8 +178,6 @@ async def send_email( ): if user_context is None: user_context = {} - if input_.tenant_id is None: - input_.tenant_id = DEFAULT_TENANT_ID return await ThirdPartyEmailPasswordRecipe.get_instance().email_delivery.ingredient_interface_impl.send_email( input_, user_context @@ -203,7 +201,7 @@ async def create_reset_password_link( recipe_instance.get_app_info(), token.token, recipe_instance.get_recipe_id(), - tenant_id or DEFAULT_TENANT_ID, + tenant_id, ) ) diff --git a/supertokens_python/recipe/thirdpartypasswordless/asyncio/__init__.py b/supertokens_python/recipe/thirdpartypasswordless/asyncio/__init__.py index 7bb72666a..61fd8c3d4 100644 --- a/supertokens_python/recipe/thirdpartypasswordless/asyncio/__init__.py +++ b/supertokens_python/recipe/thirdpartypasswordless/asyncio/__init__.py @@ -47,7 +47,7 @@ async def get_user_by_third_party_info( return await ThirdPartyPasswordlessRecipe.get_instance().recipe_implementation.get_user_by_thirdparty_info( third_party_id, third_party_user_id, - tenant_id or DEFAULT_TENANT_ID, + tenant_id, user_context, ) @@ -65,7 +65,7 @@ async def thirdparty_manually_create_or_update_user( third_party_id, third_party_user_id, email, - tenant_id or DEFAULT_TENANT_ID, + tenant_id, user_context, ) @@ -79,7 +79,7 @@ async def thirdparty_get_provider( if user_context is None: user_context = {} return await ThirdPartyPasswordlessRecipe.get_instance().recipe_implementation.thirdparty_get_provider( - third_party_id, client_type, tenant_id or DEFAULT_TENANT_ID, user_context + third_party_id, client_type, tenant_id, user_context ) @@ -89,7 +89,7 @@ async def get_users_by_email( if user_context is None: user_context = {} return await ThirdPartyPasswordlessRecipe.get_instance().recipe_implementation.get_users_by_email( - email, tenant_id or DEFAULT_TENANT_ID, user_context + email, tenant_id, user_context ) @@ -106,7 +106,7 @@ async def create_code( email=email, phone_number=phone_number, user_input_code=user_input_code, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -126,7 +126,7 @@ async def create_new_code_for_device( return await ThirdPartyPasswordlessRecipe.get_instance().recipe_implementation.create_new_code_for_device( device_id=device_id, user_input_code=user_input_code, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -151,7 +151,7 @@ async def consume_code( user_input_code=user_input_code, device_id=device_id, link_code=link_code, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -163,7 +163,7 @@ async def get_user_by_phone_number( user_context = {} return await ThirdPartyPasswordlessRecipe.get_instance().recipe_implementation.get_user_by_phone_number( phone_number=phone_number, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -220,7 +220,7 @@ async def revoke_all_codes( return await ThirdPartyPasswordlessRecipe.get_instance().recipe_implementation.revoke_all_codes( email=email, phone_number=phone_number, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -232,7 +232,7 @@ async def revoke_code( user_context = {} return await ThirdPartyPasswordlessRecipe.get_instance().recipe_implementation.revoke_code( code_id=code_id, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -243,7 +243,7 @@ async def list_codes_by_email( if user_context is None: user_context = {} return await ThirdPartyPasswordlessRecipe.get_instance().recipe_implementation.list_codes_by_email( - email=email, tenant_id=tenant_id or DEFAULT_TENANT_ID, user_context=user_context + email=email, tenant_id=tenant_id, user_context=user_context ) @@ -254,7 +254,7 @@ async def list_codes_by_phone_number( user_context = {} return await ThirdPartyPasswordlessRecipe.get_instance().recipe_implementation.list_codes_by_phone_number( phone_number=phone_number, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -266,7 +266,7 @@ async def list_codes_by_device_id( user_context = {} return await ThirdPartyPasswordlessRecipe.get_instance().recipe_implementation.list_codes_by_device_id( device_id=device_id, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -280,7 +280,7 @@ async def list_codes_by_pre_auth_session_id( user_context = {} return await ThirdPartyPasswordlessRecipe.get_instance().recipe_implementation.list_codes_by_pre_auth_session_id( pre_auth_session_id=pre_auth_session_id, - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, user_context=user_context, ) @@ -294,7 +294,7 @@ async def create_magic_link( if user_context is None: user_context = {} return await ThirdPartyPasswordlessRecipe.get_instance().passwordless_recipe.create_magic_link( - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, email=email, phone_number=phone_number, user_context=user_context, @@ -311,7 +311,7 @@ async def passwordlessSigninup( user_context = {} result = ( await ThirdPartyPasswordlessRecipe.get_instance().passwordless_recipe.signinup( - tenant_id=tenant_id or DEFAULT_TENANT_ID, + tenant_id=tenant_id, email=email, phone_number=phone_number, user_context=user_context, diff --git a/supertokens_python/recipe/userroles/asyncio/__init__.py b/supertokens_python/recipe/userroles/asyncio/__init__.py index 833d09dde..abfb1447c 100644 --- a/supertokens_python/recipe/userroles/asyncio/__init__.py +++ b/supertokens_python/recipe/userroles/asyncio/__init__.py @@ -1,6 +1,5 @@ from typing import Any, Dict, List, Union -from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID from supertokens_python.recipe.userroles.interfaces import ( AddRoleToUserOkResult, CreateNewRoleOrAddPermissionsOkResult, @@ -26,7 +25,7 @@ async def add_role_to_user( if user_context is None: user_context = {} return await UserRolesRecipe.get_instance().recipe_implementation.add_role_to_user( - role, tenant_id or DEFAULT_TENANT_ID, user_id, user_context + role, tenant_id, user_id, user_context ) @@ -39,7 +38,7 @@ async def remove_user_role( if user_context is None: user_context = {} return await UserRolesRecipe.get_instance().recipe_implementation.remove_user_role( - role, tenant_id or DEFAULT_TENANT_ID, user_id, user_context + role, tenant_id, user_id, user_context ) @@ -50,7 +49,7 @@ async def get_roles_for_user( user_context = {} return ( await UserRolesRecipe.get_instance().recipe_implementation.get_roles_for_user( - user_id, tenant_id or DEFAULT_TENANT_ID, user_context + user_id, tenant_id, user_context ) ) @@ -61,7 +60,7 @@ async def get_users_that_have_role( if user_context is None: user_context = {} return await UserRolesRecipe.get_instance().recipe_implementation.get_users_that_have_role( - role, tenant_id or DEFAULT_TENANT_ID, user_context + role, tenant_id, user_context ) diff --git a/supertokens_python/recipe/userroles/recipe_implementation.py b/supertokens_python/recipe/userroles/recipe_implementation.py index 293339c56..92c3aff5b 100644 --- a/supertokens_python/recipe/userroles/recipe_implementation.py +++ b/supertokens_python/recipe/userroles/recipe_implementation.py @@ -32,7 +32,6 @@ RemoveUserRoleOkResult, UnknownRoleError, ) -from ..multitenancy.constants import DEFAULT_TENANT_ID class RecipeImplementation(RecipeInterface): @@ -49,7 +48,7 @@ async def add_role_to_user( ) -> Union[AddRoleToUserOkResult, UnknownRoleError]: params = {"userId": user_id, "role": role} response = await self.querier.send_put_request( - NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/user/role"), + NormalisedURLPath(f"{tenant_id}/recipe/user/role"), params, ) if response.get("status") == "OK": @@ -67,9 +66,7 @@ async def remove_user_role( ) -> Union[RemoveUserRoleOkResult, UnknownRoleError]: params = {"userId": user_id, "role": role} response = await self.querier.send_post_request( - NormalisedURLPath( - f"{tenant_id or DEFAULT_TENANT_ID}/recipe/user/role/remove" - ), + NormalisedURLPath(f"{tenant_id}/recipe/user/role/remove"), params, ) if response["status"] == "OK": @@ -83,7 +80,7 @@ async def get_roles_for_user( ) -> GetRolesForUserOkResult: params = {"userId": user_id} response = await self.querier.send_get_request( - NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/user/roles"), + NormalisedURLPath(f"{tenant_id}/recipe/user/roles"), params, ) return GetRolesForUserOkResult(roles=response["roles"]) @@ -93,7 +90,7 @@ async def get_users_that_have_role( ) -> Union[GetUsersThatHaveRoleOkResult, UnknownRoleError]: params = {"role": role} response = await self.querier.send_get_request( - NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/role/users"), + NormalisedURLPath(f"{tenant_id}/recipe/role/users"), params, ) if response.get("status") == "OK": diff --git a/supertokens_python/recipe_module.py b/supertokens_python/recipe_module.py index 4ff46728a..937964b8f 100644 --- a/supertokens_python/recipe_module.py +++ b/supertokens_python/recipe_module.py @@ -94,7 +94,7 @@ async def return_api_id_if_can_handle_request( ).equals(self.app_info.api_base_path.append(remaining_path)): final_tenant_id = ( await mt_recipe.recipe_implementation.get_tenant_id( - tenant_id or DEFAULT_TENANT_ID, user_context + tenant_id, user_context ) ) return ApiIdWithTenantId(current_api.request_id, final_tenant_id)