Skip to content

Commit

Permalink
refactor: Revert session related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KShivendu committed Jul 19, 2023
1 parent f8eb3f4 commit 93500de
Show file tree
Hide file tree
Showing 40 changed files with 98 additions and 179 deletions.
2 changes: 0 additions & 2 deletions supertokens_python/recipe/emailpassword/api/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ async def sign_in_post(
user = result.user
session = await create_new_session(
api_options.request,
"pass-tenant-id", # TODO: change this to tenant_id
user.user_id,
access_token_payload={},
session_data_in_database={},
Expand Down Expand Up @@ -210,7 +209,6 @@ async def sign_up_post(
user = result.user
session = await create_new_session(
api_options.request,
"pass-tenant-id", # TODO: change this to tenant_id
user.user_id,
access_token_payload={},
session_data_in_database={},
Expand Down
3 changes: 1 addition & 2 deletions supertokens_python/recipe/multitenancy/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,5 @@ async def login_methods_get(


TypeGetAllowedDomainsForTenantId = Callable[
[Optional[str], Dict[str, Any]],
Awaitable[Optional[List[str]]]
[Optional[str], Dict[str, Any]], Awaitable[Optional[List[str]]]
]
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ async def consume_code_post(

session = await create_new_session(
api_options.request,
"pass-tenant-id", # TODO: change this to tenant_id
user.user_id,
{},
{},
Expand Down
6 changes: 1 addition & 5 deletions supertokens_python/recipe/session/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@

async def create_new_session(
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,
Expand All @@ -67,7 +66,6 @@ async def create_new_session(

return await create_new_session_in_request(
request,
tenant_id,
user_context,
recipe_instance,
access_token_payload,
Expand All @@ -79,7 +77,6 @@ async def create_new_session(


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,
Expand All @@ -105,11 +102,10 @@ 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, user_context)
update = await claim.build(user_id, user_context)
final_access_token_payload = {**final_access_token_payload, **update}

return await SessionRecipe.get_instance().recipe_implementation.create_new_session(
tenant_id,
user_id,
final_access_token_payload,
session_data_in_database,
Expand Down
18 changes: 4 additions & 14 deletions supertokens_python/recipe/session/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def __init__(
expiry: int,
custom_claims_in_access_token_payload: Dict[str, Any],
time_created: int,
tenant_id: str,
):
self.session_handle: str = session_handle
self.user_id: str = user_id
Expand All @@ -79,7 +78,6 @@ def __init__(
str, Any
] = custom_claims_in_access_token_payload
self.time_created: int = time_created
self.tenant_id: str = tenant_id


class ReqResInfo:
Expand Down Expand Up @@ -135,7 +133,6 @@ def __init__(self):
@abstractmethod
async def create_new_session(
self,
tenant_id: str,
user_id: str,
access_token_payload: Optional[Dict[str, Any]],
session_data_in_database: Optional[Dict[str, Any]],
Expand Down Expand Up @@ -386,7 +383,6 @@ def __init__(
user_data_in_access_token: Optional[Dict[str, Any]],
req_res_info: Optional[ReqResInfo],
access_token_updated: bool,
tenant_id: str,
):
self.recipe_implementation = recipe_implementation
self.config = config
Expand All @@ -399,7 +395,6 @@ def __init__(
self.user_data_in_access_token = user_data_in_access_token
self.req_res_info: Optional[ReqResInfo] = req_res_info
self.access_token_updated = access_token_updated
self.tenant_id = tenant_id

self.response_mutators: List[ResponseMutator] = []

Expand Down Expand Up @@ -441,10 +436,6 @@ async def merge_into_access_token_payload(
def get_user_id(self, user_context: Optional[Dict[str, Any]] = None) -> str:
pass

@abstractmethod
def get_tenant_id(self, user_context: Optional[Dict[str, Any]] = None) -> str:
pass

@abstractmethod
def get_access_token_payload(
self, user_context: Optional[Dict[str, Any]] = None
Expand Down Expand Up @@ -637,14 +628,13 @@ def get_value_from_payload(
"""Gets the value of the claim stored in the payload"""

async def build(
self,
user_id: str,
tenant_id: str,
user_context: Optional[Dict[str, Any]] = None,
self, user_id: str, user_context: Optional[Dict[str, Any]] = None
) -> JSONObject:
if user_context is None:
user_context = {}
value = await resolve(self.fetch_value(user_id, tenant_id, user_context))

# TODO: change this to tenant_id
value = await resolve(self.fetch_value(user_id, "pass-tenant-id", user_context))

if value is None:
return {}
Expand Down
6 changes: 1 addition & 5 deletions supertokens_python/recipe/session/recipe_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def __init__(self, querier: Querier, config: SessionConfig, app_info: AppInfo):

async def create_new_session(
self,
tenant_id: str,
user_id: str,
access_token_payload: Optional[Dict[str, Any]],
session_data_in_database: Optional[Dict[str, Any]],
Expand Down Expand Up @@ -96,7 +95,6 @@ async def create_new_session(
payload,
None,
True,
tenant_id,
)

return new_session
Expand Down Expand Up @@ -264,7 +262,6 @@ async def get_session(
payload,
None,
access_token_updated,
response.session.tenantId,
)

return session
Expand Down Expand Up @@ -315,7 +312,6 @@ async def refresh_session(
user_data_in_access_token=payload,
req_res_info=None,
access_token_updated=True,
tenant_id=payload["tId"],
)

return session
Expand Down Expand Up @@ -388,7 +384,7 @@ async def fetch_and_set_claim(
return False

access_token_payload_update = await claim.build(
session_info.user_id, session_info.tenant_id, user_context
session_info.user_id, user_context
)
return await self.merge_into_access_token_payload(
session_handle, access_token_payload_update, user_context
Expand Down
9 changes: 2 additions & 7 deletions supertokens_python/recipe/session/session_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, TypeVar, Union, Optional
from typing import Any, Dict, List, TypeVar, Union

from supertokens_python.recipe.session.exceptions import (
raise_invalid_claims_exception,
Expand Down Expand Up @@ -133,9 +133,6 @@ async def update_session_data_in_database(
def get_user_id(self, user_context: Union[Dict[str, Any], None] = None) -> str:
return self.user_id

def get_tenant_id(self, user_context: Optional[Dict[str, Any]] = None) -> str:
return self.tenant_id

def get_access_token_payload(
self, user_context: Union[Dict[str, Any], None] = None
) -> Dict[str, Any]:
Expand Down Expand Up @@ -223,9 +220,7 @@ async def fetch_and_set_claim(
if user_context is None:
user_context = {}

update = await claim.build(
self.get_user_id(), self.get_tenant_id(), user_context
)
update = await claim.build(self.get_user_id(), user_context)
return await self.merge_into_access_token_payload(update, user_context)

async def set_claim_value(
Expand Down
5 changes: 0 additions & 5 deletions supertokens_python/recipe/session/session_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ def __init__(
userId: str,
userDataInJWT: Dict[str, Any],
expiryTime: int,
tenantId: str,
) -> None:
self.handle = handle
self.userId = userId
self.userDataInJWT = userDataInJWT
self.expiryTime = expiryTime
self.tenantId = tenantId


class GetSessionAPIResponseAccessToken:
Expand Down Expand Up @@ -256,7 +254,6 @@ async def get_session(
access_token_info["userId"],
access_token_info["userData"],
access_token_info["expiryTime"],
access_token_info["tenantId"],
)
)

Expand Down Expand Up @@ -295,7 +292,6 @@ async def get_session(
"expiryTime"
] # 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"]["tenantId"],
),
GetSessionAPIResponseAccessToken(
response["accessToken"]["token"],
Expand Down Expand Up @@ -459,6 +455,5 @@ async def get_session_information(
response["expiry"],
response["userDataInJWT"],
response["timeCreated"],
response["tenantId"],
)
return None
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ async def get_session_from_request(

async def create_new_session_in_request(
request: Any,
tenant_id: str,
user_context: Dict[str, Any],
recipe_instance: SessionRecipe,
access_token_payload: Dict[str, Any],
Expand Down Expand Up @@ -239,7 +238,7 @@ async def create_new_session_in_request(
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, user_context)
update = await claim.build(user_id, user_context)
final_access_token_payload = {**final_access_token_payload, **update}

log_debug_message("createNewSession: Access token payload built")
Expand Down Expand Up @@ -276,7 +275,6 @@ async def create_new_session_in_request(

disable_anti_csrf = output_transfer_method == "header"
session = await recipe_instance.recipe_implementation.create_new_session(
tenant_id,
user_id,
final_access_token_payload,
session_data_in_database,
Expand Down
4 changes: 0 additions & 4 deletions supertokens_python/recipe/session/syncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

def create_new_session(
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,
Expand All @@ -53,7 +52,6 @@ def create_new_session(
return sync(
async_create_new_session(
request,
tenant_id,
user_id,
access_token_payload,
session_data_in_database,
Expand All @@ -63,7 +61,6 @@ def create_new_session(


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,
Expand All @@ -76,7 +73,6 @@ 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,
Expand Down
1 change: 0 additions & 1 deletion supertokens_python/recipe/thirdparty/api/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ async def sign_in_up_post(
user = signinup_response.user
session = await create_new_session(
api_options.request,
"pass-tenant-id", # TODO: change this to tenant_id
user.user_id,
user_context=user_context,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/Django/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "public", "user_id")
await create_new_session(request, "user_id")
return JsonResponse({"foo": "bar"})


Expand Down
6 changes: 3 additions & 3 deletions tests/Fastapi/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "public", user_id, {}, {})
await create_new_session(request, user_id, {}, {})
return {"userId": user_id}

@app.post("/refresh")
Expand Down Expand Up @@ -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, "public", "userId", {}, {})
await create_new_session(request, "userId", {}, {})
return ""

@app.post("/create-throw")
async def _create_throw(request: Request): # type: ignore
await create_new_session(request, "public", "userId", {}, {})
await create_new_session(request, "userId", {}, {})
raise UnauthorisedError("unauthorised")

return TestClient(app)
Expand Down
4 changes: 2 additions & 2 deletions tests/Flask/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def t(): # type: ignore
@app.route("/login") # type: ignore
def login(): # type: ignore
user_id = "userId"
create_new_session(request, "public", user_id, {}, {})
create_new_session(request, user_id, {}, {})

return jsonify({"userId": user_id, "session": "ssss"})

Expand Down Expand Up @@ -745,7 +745,7 @@ def test_api(): # type: ignore
@app.route("/login") # type: ignore
def login(): # type: ignore
user_id = "userId"
s = create_new_session(request, "public", user_id, {}, {})
s = create_new_session(request, user_id, {}, {})
return jsonify({"user": s.get_user_id()})

@app.route("/ping") # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion tests/emailpassword/test_emailexists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "public", user_id, {}, {})
await create_new_session(request, user_id, {}, {})
return {"userId": user_id}

@app.post("/refresh")
Expand Down
2 changes: 1 addition & 1 deletion tests/emailpassword/test_emailverify.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def driver_config_client():
@app.get("/login")
async def login(request: Request): # type: ignore
user_id = "userId"
await create_new_session(request, "public", user_id, {}, {})
await create_new_session(request, user_id, {}, {})
return {"userId": user_id}

@app.post("/refresh")
Expand Down
2 changes: 1 addition & 1 deletion tests/emailpassword/test_passwordreset.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def driver_config_client():
@app.get("/login")
async def login(request: Request): # type: ignore
user_id = "userId"
await create_new_session(request, "public", user_id, {}, {})
await create_new_session(request, user_id, {}, {})
return {"userId": user_id}

@app.post("/refresh")
Expand Down
2 changes: 1 addition & 1 deletion tests/emailpassword/test_signin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "public", user_id, {}, {})
await create_new_session(request, user_id, {}, {})
return {"userId": user_id}

@app.post("/refresh")
Expand Down
Loading

0 comments on commit 93500de

Please sign in to comment.