Skip to content

Commit

Permalink
Merge branch 'feat/tp-rework' into tenant-id-compulsory
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar authored Aug 11, 2023
2 parents 0e10bf5 + f16623e commit 84acec2
Show file tree
Hide file tree
Showing 29 changed files with 87 additions and 162 deletions.
23 changes: 0 additions & 23 deletions supertokens_python/always_initialised_recipes.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

async def handle_sessions_get(
_api_interface: APIInterface,
_tenant_id: str,
tenant_id: str,
api_options: APIOptions,
user_context: Dict[str, Any],
) -> UserSessionsGetAPIResponse:
Expand All @@ -26,9 +26,10 @@ async def handle_sessions_get(
if user_id is None:
raise_bad_input_exception("Missing required parameter 'userId'")

# TODO: Pass tenant id here
# Passing tenant id as None sets fetch_across_all_tenants to True
# which is what we want here.
session_handles = await get_all_session_handles_for_user(
user_id, "pass-tenant-id", user_context
user_id, None, user_context
)
sessions: List[Optional[SessionInfo]] = [None for _ in session_handles]

Expand Down
8 changes: 4 additions & 4 deletions supertokens_python/recipe/emailpassword/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
CreateResetPasswordWrongUserIdError,
CreateResetPasswordLinkUknownUserIdError,
CreateResetPasswordLinkOkResult,
CreateResetPasswordEmailOkResult,
CreateResetPasswordEmailUnknownUserIdError,
SendResetPasswordEmailOkResult,
SendResetPasswordEmailUnknownUserIdError,
)
from supertokens_python.recipe.emailpassword.utils import get_password_reset_link
from supertokens_python.recipe.emailpassword.types import (
Expand Down Expand Up @@ -157,7 +157,7 @@ async def send_reset_password_email(
):
link = await create_reset_password_link(tenant_id, user_id, user_context)
if isinstance(link, CreateResetPasswordLinkUknownUserIdError):
return CreateResetPasswordEmailUnknownUserIdError()
return SendResetPasswordEmailUnknownUserIdError()

user = await get_user_by_id(user_id, user_context)
assert user is not None
Expand All @@ -171,4 +171,4 @@ async def send_reset_password_email(
user_context,
)

return CreateResetPasswordEmailOkResult()
return SendResetPasswordEmailOkResult()
4 changes: 2 additions & 2 deletions supertokens_python/recipe/emailpassword/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ class CreateResetPasswordLinkUknownUserIdError:
pass


class CreateResetPasswordEmailOkResult:
class SendResetPasswordEmailOkResult:
pass


class CreateResetPasswordEmailUnknownUserIdError:
class SendResetPasswordEmailUnknownUserIdError:
pass


Expand Down
2 changes: 1 addition & 1 deletion supertokens_python/recipe/emailverification/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def callback():
PostSTInitCallbacks.add_post_init_callback(callback)

return EmailVerificationRecipe.__instance
return raise_general_exception(
raise_general_exception(
"Emailverification recipe has already been initialised. Please check your code for bugs."
)

Expand Down
8 changes: 4 additions & 4 deletions supertokens_python/recipe/session/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ async def validate_claims_for_session_handle(
)
global_claim_validators = await resolve(
recipe_impl.get_global_claim_validators(
session_info.user_id,
session_info.tenant_id,
session_info.user_id,
claim_validators_added_by_other_recipes,
user_context,
)
Expand Down Expand Up @@ -188,8 +188,8 @@ async def validate_claims_for_session_handle(


async def validate_claims_in_jwt_payload(
user_id: str,
tenant_id: str,
user_id: str,
jwt_payload: JSONObject,
override_global_claim_validators: Optional[
Callable[
Expand All @@ -213,8 +213,8 @@ async def validate_claims_in_jwt_payload(
)
global_claim_validators = await resolve(
recipe_impl.get_global_claim_validators(
user_id,
tenant_id,
user_id,
claim_validators_added_by_other_recipes,
user_context,
)
Expand Down Expand Up @@ -444,7 +444,7 @@ async def revoke_all_sessions_for_user(

async def get_all_session_handles_for_user(
user_id: str,
tenant_id: Optional[str],
tenant_id: Optional[str] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> List[str]:
if user_context is None:
Expand Down
6 changes: 3 additions & 3 deletions supertokens_python/recipe/session/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ async def create_new_session(
@abstractmethod
def get_global_claim_validators(
self,
user_id: str,
tenant_id: str,
user_id: str,
claim_validators_added_by_other_recipes: List[SessionClaimValidator],
user_context: Dict[str, Any],
) -> MaybeAwaitable[List[SessionClaimValidator]]:
Expand Down Expand Up @@ -220,7 +220,7 @@ async def revoke_all_sessions_for_user(
self,
user_id: str,
tenant_id: str,
revoke_across_all_tenants: Optional[bool],
revoke_across_all_tenants: bool,
user_context: Dict[str, Any],
) -> List[str]:
pass
Expand All @@ -230,7 +230,7 @@ async def get_all_session_handles_for_user(
self,
user_id: str,
tenant_id: str,
fetch_across_all_tenants: Optional[bool],
fetch_across_all_tenants: bool,
user_context: Dict[str, Any],
) -> List[str]:
pass
Expand Down
6 changes: 3 additions & 3 deletions supertokens_python/recipe/session/recipe_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ async def revoke_all_sessions_for_user(
self,
user_id: str,
tenant_id: Optional[str],
revoke_across_all_tenants: Optional[bool],
revoke_across_all_tenants: bool,
user_context: Dict[str, Any],
) -> List[str]:
return await session_functions.revoke_all_sessions_for_user(
Expand All @@ -341,7 +341,7 @@ async def get_all_session_handles_for_user(
self,
user_id: str,
tenant_id: Optional[str],
fetch_across_all_tenants: Optional[bool],
fetch_across_all_tenants: bool,
user_context: Dict[str, Any],
) -> List[str]:
return await session_functions.get_all_session_handles_for_user(
Expand Down Expand Up @@ -437,8 +437,8 @@ async def get_claim_value(

def get_global_claim_validators(
self,
user_id: str,
tenant_id: str,
user_id: str,
claim_validators_added_by_other_recipes: List[SessionClaimValidator],
user_context: Dict[str, Any],
) -> MaybeAwaitable[List[SessionClaimValidator]]:
Expand Down
5 changes: 3 additions & 2 deletions supertokens_python/recipe/session/session_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ async def fetch_and_set_claim(
if user_context is None:
user_context = {}

# TODO: Pass tenant id
update = await claim.build(self.get_user_id(), "pass-tenant-id", user_context)
update = await claim.build(
self.get_user_id(), self.get_tenant_id(), user_context
)
return await self.merge_into_access_token_payload(update, user_context)

async def set_claim_value(
Expand Down
4 changes: 2 additions & 2 deletions supertokens_python/recipe/session/session_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ async def revoke_all_sessions_for_user(
recipe_implementation: RecipeImplementation,
user_id: str,
tenant_id: Optional[str],
revoke_across_all_tenants: Optional[bool],
revoke_across_all_tenants: bool,
) -> List[str]:
if tenant_id is None:
tenant_id = DEFAULT_TENANT_ID
Expand All @@ -405,7 +405,7 @@ async def get_all_session_handles_for_user(
recipe_implementation: RecipeImplementation,
user_id: str,
tenant_id: Optional[str],
fetch_across_all_tenants: Optional[bool],
fetch_across_all_tenants: bool,
) -> List[str]:
if tenant_id is None:
tenant_id = DEFAULT_TENANT_ID
Expand Down
4 changes: 2 additions & 2 deletions supertokens_python/recipe/session/syncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ def validate_claims_for_session_handle(


def validate_claims_in_jwt_payload(
user_id: str,
tenant_id: str,
user_id: str,
jwt_payload: JSONObject,
override_global_claim_validators: Optional[
Callable[
Expand All @@ -402,8 +402,8 @@ def validate_claims_in_jwt_payload(

return sync(
async_validate_claims_in_jwt_payload(
user_id,
tenant_id,
user_id,
jwt_payload,
override_global_claim_validators,
user_context,
Expand Down
2 changes: 1 addition & 1 deletion supertokens_python/recipe/session/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ async def get_required_claim_validators(
)
global_claim_validators = await resolve(
SessionRecipe.get_instance().recipe_implementation.get_global_claim_validators(
session.get_user_id(),
session.get_tenant_id(),
session.get_user_id(),
claim_validators_added_by_other_recipes,
user_context,
)
Expand Down
1 change: 1 addition & 0 deletions supertokens_python/recipe/thirdparty/api/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
CreateResetPasswordWrongUserIdError,
CreateResetPasswordLinkUknownUserIdError,
CreateResetPasswordLinkOkResult,
CreateResetPasswordEmailUnknownUserIdError,
CreateResetPasswordEmailOkResult,
RawUserInfoFromProvider,
SendResetPasswordEmailUnknownUserIdError,
SendResetPasswordEmailEmailOkResult
)
from supertokens_python.recipe.emailpassword.utils import get_password_reset_link

Expand Down Expand Up @@ -62,30 +61,6 @@ async def get_user_by_third_party_info(
user_context,
)


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,
user_context: Optional[Dict[str, Any]] = None,
):
if user_context is None:
user_context = {}

return await ThirdPartyEmailPasswordRecipe.get_instance().recipe_implementation.thirdparty_sign_in_up(
third_party_id,
third_party_user_id,
email,
oauth_tokens,
raw_user_info_from_provider,
tenant_id or DEFAULT_TENANT_ID,
user_context,
)


async def thirdparty_manually_create_or_update_user(
tenant_id: str,
third_party_id: str,
Expand Down Expand Up @@ -239,7 +214,7 @@ async def send_reset_password_email(
):
link = await create_reset_password_link(tenant_id, user_id, user_context)
if isinstance(link, CreateResetPasswordLinkUknownUserIdError):
return CreateResetPasswordEmailUnknownUserIdError()
return SendResetPasswordEmailUnknownUserIdError()

user = await get_user_by_id(user_id, user_context)
assert user is not None
Expand All @@ -253,4 +228,4 @@ async def send_reset_password_email(
user_context,
)

return CreateResetPasswordEmailOkResult()
return SendResetPasswordEmailEmailOkResult()
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
CreateResetPasswordLinkUknownUserIdError = (
EPInterfaces.CreateResetPasswordLinkUknownUserIdError
)
CreateResetPasswordEmailOkResult = EPInterfaces.CreateResetPasswordEmailOkResult
CreateResetPasswordEmailUnknownUserIdError = (
EPInterfaces.CreateResetPasswordEmailUnknownUserIdError
SendResetPasswordEmailEmailOkResult = EPInterfaces.SendResetPasswordEmailOkResult
SendResetPasswordEmailUnknownUserIdError = (
EPInterfaces.SendResetPasswordEmailUnknownUserIdError
)
EmailPasswordEmailExistsGetOkResult = EPInterfaces.EmailExistsGetOkResult
GeneratePasswordResetTokenPostOkResult = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from ..interfaces import (
EmailPasswordSignInOkResult,
EmailPasswordSignInWrongCredentialsError,
RawUserInfoFromProvider,
)
from ..types import EmailTemplateVars, User

Expand Down Expand Up @@ -49,32 +48,6 @@ def get_user_by_third_party_info(
)


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,
user_context: Optional[Dict[str, Any]] = None,
):
from supertokens_python.recipe.thirdpartyemailpassword.asyncio import (
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,
user_context,
)
)


def thirdparty_manually_create_or_update_user(
tenant_id: str,
third_party_id: str,
Expand Down
4 changes: 2 additions & 2 deletions supertokens_python/recipe/userroles/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async def fetch_value(
recipe = UserRolesRecipe.get_instance()

user_roles = await recipe.recipe_implementation.get_roles_for_user(
tenant_id, user_id, user_context
user_id, tenant_id, user_context
)

user_permissions: Set[str] = set()
Expand Down Expand Up @@ -186,7 +186,7 @@ async def fetch_value(
) -> List[str]:
recipe = UserRolesRecipe.get_instance()
res = await recipe.recipe_implementation.get_roles_for_user(
tenant_id, user_id, user_context
user_id, tenant_id, user_context
)
return res.roles

Expand Down
Loading

0 comments on commit 84acec2

Please sign in to comment.