Skip to content

Commit 5c483cb

Browse files
committed
chores: Format
1 parent c2c85b7 commit 5c483cb

File tree

6 files changed

+75
-34
lines changed

6 files changed

+75
-34
lines changed

supertokens_python/recipe/session/access_token.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ def validate_access_token_structure(payload: Dict[str, Any], version: int) -> No
155155

156156
if version >= 4:
157157
if not isinstance(payload.get("tId"), str):
158-
raise Exception("Access token does not contain all the information. Maybe the structure has changed?")
158+
raise Exception(
159+
"Access token does not contain all the information. Maybe the structure has changed?"
160+
)
159161

160162
elif (
161163
not isinstance(payload.get("sessionHandle"), str)

supertokens_python/recipe/session/asyncio/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,18 +426,21 @@ async def revoke_session(
426426

427427

428428
async def revoke_all_sessions_for_user(
429-
user_id: str, tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None
429+
user_id: str,
430+
tenant_id: Optional[str] = None,
431+
user_context: Union[None, Dict[str, Any]] = None,
430432
) -> List[str]:
431433
if user_context is None:
432434
user_context = {}
433435
return await SessionRecipe.get_instance().recipe_implementation.revoke_all_sessions_for_user(
434-
user_id, tenant_id or DEFAULT_TENANT_ID,
435-
tenant_id is None, user_context
436+
user_id, tenant_id or DEFAULT_TENANT_ID, tenant_id is None, user_context
436437
)
437438

438439

439440
async def get_all_session_handles_for_user(
440-
user_id: str, tenant_id: Optional[str], user_context: Union[None, Dict[str, Any]] = None
441+
user_id: str,
442+
tenant_id: Optional[str],
443+
user_context: Union[None, Dict[str, Any]] = None,
441444
) -> List[str]:
442445
if user_context is None:
443446
user_context = {}

supertokens_python/recipe/session/interfaces.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@
4141

4242

4343
class SessionObj:
44-
def __init__(self, handle: str, user_id: str, user_data_in_jwt: Dict[str, Any], tenant_id: str):
44+
def __init__(
45+
self,
46+
handle: str,
47+
user_id: str,
48+
user_data_in_jwt: Dict[str, Any],
49+
tenant_id: str,
50+
):
4551
self.handle = handle
4652
self.user_id = user_id
4753
self.user_data_in_jwt = user_data_in_jwt
@@ -76,7 +82,9 @@ def __init__(
7682
self.user_id = user_id
7783
self.session_data_in_database = session_data_in_database
7884
self.expiry = expiry
79-
self.custom_claims_in_access_token_payload = custom_claims_in_access_token_payload
85+
self.custom_claims_in_access_token_payload = (
86+
custom_claims_in_access_token_payload
87+
)
8088
self.time_created = time_created
8189
self.tenant_id = tenant_id
8290

@@ -208,13 +216,21 @@ async def revoke_session(
208216

209217
@abstractmethod
210218
async def revoke_all_sessions_for_user(
211-
self, user_id: str, tenant_id: str, revoke_across_all_tenants: Optional[bool], user_context: Dict[str, Any]
219+
self,
220+
user_id: str,
221+
tenant_id: str,
222+
revoke_across_all_tenants: Optional[bool],
223+
user_context: Dict[str, Any],
212224
) -> List[str]:
213225
pass
214226

215227
@abstractmethod
216228
async def get_all_session_handles_for_user(
217-
self, user_id: str, tenant_id: str, fetch_across_all_tenants: Optional[bool], user_context: Dict[str, Any]
229+
self,
230+
user_id: str,
231+
tenant_id: str,
232+
fetch_across_all_tenants: Optional[bool],
233+
user_context: Dict[str, Any],
218234
) -> List[str]:
219235
pass
220236

supertokens_python/recipe/session/recipe_implementation.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def create_new_session(
7575
disable_anti_csrf is True,
7676
access_token_payload,
7777
session_data_in_database,
78-
tenant_id
78+
tenant_id,
7979
)
8080
log_debug_message("createNewSession: Finished")
8181

@@ -97,7 +97,7 @@ async def create_new_session(
9797
payload,
9898
None,
9999
True,
100-
tenant_id
100+
tenant_id,
101101
)
102102

103103
return new_session
@@ -327,14 +327,26 @@ async def revoke_session(
327327
return await session_functions.revoke_session(self, session_handle)
328328

329329
async def revoke_all_sessions_for_user(
330-
self, user_id: str, tenant_id: Optional[str], revoke_across_all_tenants: Optional[bool], user_context: Dict[str, Any]
330+
self,
331+
user_id: str,
332+
tenant_id: Optional[str],
333+
revoke_across_all_tenants: Optional[bool],
334+
user_context: Dict[str, Any],
331335
) -> List[str]:
332-
return await session_functions.revoke_all_sessions_for_user(self, user_id, tenant_id, revoke_across_all_tenants)
336+
return await session_functions.revoke_all_sessions_for_user(
337+
self, user_id, tenant_id, revoke_across_all_tenants
338+
)
333339

334340
async def get_all_session_handles_for_user(
335-
self, user_id: str, tenant_id: Optional[str], fetch_across_all_tenants: Optional[bool], user_context: Dict[str, Any]
341+
self,
342+
user_id: str,
343+
tenant_id: Optional[str],
344+
fetch_across_all_tenants: Optional[bool],
345+
user_context: Dict[str, Any],
336346
) -> List[str]:
337-
return await session_functions.get_all_session_handles_for_user(self, user_id, tenant_id, fetch_across_all_tenants)
347+
return await session_functions.get_all_session_handles_for_user(
348+
self, user_id, tenant_id, fetch_across_all_tenants
349+
)
338350

339351
async def revoke_multiple_sessions(
340352
self, session_handles: List[str], user_context: Dict[str, Any]
@@ -467,6 +479,6 @@ async def regenerate_access_token(
467479
response["session"]["handle"],
468480
response["session"]["userId"],
469481
response["session"]["userDataInJWT"],
470-
response["session"]["tenantId"]
482+
response["session"]["tenantId"],
471483
)
472484
return RegenerateAccessTokenOkResult(session, access_token_obj)

supertokens_python/recipe/session/session_functions.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def create_new_session(
101101
disable_anti_csrf: bool,
102102
access_token_payload: Union[None, Dict[str, Any]],
103103
session_data_in_database: Union[None, Dict[str, Any]],
104-
tenant_id: Optional[str]
104+
tenant_id: Optional[str],
105105
) -> CreateOrRefreshAPIResponse:
106106
if session_data_in_database is None:
107107
session_data_in_database = {}
@@ -263,7 +263,7 @@ async def get_session(
263263
access_token_info["userId"],
264264
access_token_info["userData"],
265265
access_token_info["expiryTime"],
266-
access_token_info["tenantId"]
266+
access_token_info["tenantId"],
267267
)
268268
)
269269

@@ -302,7 +302,9 @@ async def get_session(
302302
"expiryTime"
303303
] # 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.
304304
), # This will throw error if others are none and 'expiryTime' key doesn't exist in the payload
305-
response["session"].get("tenantId") or (access_token_info or {}).get("tenantId") or DEFAULT_TENANT_ID,
305+
response["session"].get("tenantId")
306+
or (access_token_info or {}).get("tenantId")
307+
or DEFAULT_TENANT_ID,
306308
),
307309
GetSessionAPIResponseAccessToken(
308310
response["accessToken"]["token"],
@@ -387,32 +389,33 @@ async def refresh_session(
387389

388390

389391
async def revoke_all_sessions_for_user(
390-
recipe_implementation: RecipeImplementation, user_id: str,
391-
tenant_id: Optional[str], revoke_across_all_tenants: Optional[bool],
392+
recipe_implementation: RecipeImplementation,
393+
user_id: str,
394+
tenant_id: Optional[str],
395+
revoke_across_all_tenants: Optional[bool],
392396
) -> List[str]:
393397
if tenant_id is None:
394398
tenant_id = DEFAULT_TENANT_ID
395399

396400
response = await recipe_implementation.querier.send_post_request(
397401
NormalisedURLPath(f"{tenant_id}/recipe/session/remove"),
398-
{
399-
"userId": user_id,
400-
"revokeAcrossAllTenants": revoke_across_all_tenants
401-
}
402+
{"userId": user_id, "revokeAcrossAllTenants": revoke_across_all_tenants},
402403
)
403404
return response["sessionHandlesRevoked"]
404405

405406

406407
async def get_all_session_handles_for_user(
407-
recipe_implementation: RecipeImplementation, user_id: str,
408-
tenant_id: Optional[str], fetch_across_all_tenants: Optional[bool]
408+
recipe_implementation: RecipeImplementation,
409+
user_id: str,
410+
tenant_id: Optional[str],
411+
fetch_across_all_tenants: Optional[bool],
409412
) -> List[str]:
410413
if tenant_id is None:
411414
tenant_id = DEFAULT_TENANT_ID
412415

413416
response = await recipe_implementation.querier.send_get_request(
414417
NormalisedURLPath(f"{tenant_id}/recipe/session/user"),
415-
{"userId": user_id, "fetchAcrossAllTenants": fetch_across_all_tenants}
418+
{"userId": user_id, "fetchAcrossAllTenants": fetch_across_all_tenants},
416419
)
417420
return response["sessionHandles"]
418421

@@ -431,8 +434,7 @@ async def revoke_multiple_sessions(
431434
recipe_implementation: RecipeImplementation, session_handles: List[str]
432435
) -> List[str]:
433436
response = await recipe_implementation.querier.send_post_request(
434-
NormalisedURLPath("/recipe/session/remove"),
435-
{"sessionHandles": session_handles}
437+
NormalisedURLPath("/recipe/session/remove"), {"sessionHandles": session_handles}
436438
)
437439
return response["sessionHandlesRevoked"]
438440

@@ -481,6 +483,6 @@ async def get_session_information(
481483
response["expiry"],
482484
response["userDataInJWT"],
483485
response["timeCreated"],
484-
response["tenantId"]
486+
response["tenantId"],
485487
)
486488
return None

supertokens_python/recipe/session/syncio/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ def revoke_session(
187187

188188

189189
def revoke_all_sessions_for_user(
190-
user_id: str, tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None
190+
user_id: str,
191+
tenant_id: Optional[str] = None,
192+
user_context: Union[None, Dict[str, Any]] = None,
191193
) -> List[str]:
192194
from supertokens_python.recipe.session.asyncio import (
193195
revoke_all_sessions_for_user as async_revoke_all_sessions_for_user,
@@ -197,13 +199,17 @@ def revoke_all_sessions_for_user(
197199

198200

199201
def get_all_session_handles_for_user(
200-
user_id: str, tenant_id: Optional[str] = None, user_context: Union[None, Dict[str, Any]] = None
202+
user_id: str,
203+
tenant_id: Optional[str] = None,
204+
user_context: Union[None, Dict[str, Any]] = None,
201205
) -> List[str]:
202206
from supertokens_python.recipe.session.asyncio import (
203207
get_all_session_handles_for_user as async_get_all_session_handles_for_user,
204208
)
205209

206-
return sync(async_get_all_session_handles_for_user(user_id, tenant_id, user_context))
210+
return sync(
211+
async_get_all_session_handles_for_user(user_id, tenant_id, user_context)
212+
)
207213

208214

209215
def revoke_multiple_sessions(

0 commit comments

Comments
 (0)