Skip to content

Commit 45dd912

Browse files
committed
adding dev-v0.13.1 tag to this commit to ensure building
1 parent 0fab4af commit 45dd912

File tree

4 files changed

+104
-61
lines changed

4 files changed

+104
-61
lines changed

html/supertokens_python/constants.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ <h1 class="title">Module <code>supertokens_python.constants</code></h1>
4242
from __future__ import annotations
4343

4444
SUPPORTED_CDI_VERSIONS = [&#34;2.21&#34;]
45-
VERSION = &#34;0.13.0&#34;
45+
VERSION = &#34;0.13.1&#34;
4646
TELEMETRY = &#34;/telemetry&#34;
4747
USER_COUNT = &#34;/users/count&#34;
4848
USER_DELETE = &#34;/user/remove&#34;

html/supertokens_python/recipe/session/interfaces.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ <h1 class="title">Module <code>supertokens_python.recipe.session.interfaces</cod
184184
@abstractmethod
185185
async def get_session(
186186
self,
187-
access_token: str,
188-
anti_csrf_token: Optional[str],
187+
access_token: Optional[str],
188+
anti_csrf_token: Optional[str] = None,
189189
anti_csrf_check: Optional[bool] = None,
190190
session_required: Optional[bool] = None,
191191
check_database: Optional[bool] = None,
@@ -1033,8 +1033,8 @@ <h3>Class variables</h3>
10331033
@abstractmethod
10341034
async def get_session(
10351035
self,
1036-
access_token: str,
1037-
anti_csrf_token: Optional[str],
1036+
access_token: Optional[str],
1037+
anti_csrf_token: Optional[str] = None,
10381038
anti_csrf_check: Optional[bool] = None,
10391039
session_required: Optional[bool] = None,
10401040
check_database: Optional[bool] = None,
@@ -1284,7 +1284,7 @@ <h3>Methods</h3>
12841284
</details>
12851285
</dd>
12861286
<dt id="supertokens_python.recipe.session.interfaces.RecipeInterface.get_session"><code class="name flex">
1287-
<span>async def <span class="ident">get_session</span></span>(<span>self, access_token: str, anti_csrf_token: Optional[str], anti_csrf_check: Optional[bool] = None, session_required: Optional[bool] = None, check_database: Optional[bool] = None, override_global_claim_validators: Optional[Callable[[List[<a title="supertokens_python.recipe.session.interfaces.SessionClaimValidator" href="#supertokens_python.recipe.session.interfaces.SessionClaimValidator">SessionClaimValidator</a>], <a title="supertokens_python.recipe.session.interfaces.SessionContainer" href="#supertokens_python.recipe.session.interfaces.SessionContainer">SessionContainer</a>, Dict[str, Any]], MaybeAwaitable[List[<a title="supertokens_python.recipe.session.interfaces.SessionClaimValidator" href="#supertokens_python.recipe.session.interfaces.SessionClaimValidator">SessionClaimValidator</a>]]]] = None, user_context: Optional[Dict[str, Any]] = None) ‑> Optional[<a title="supertokens_python.recipe.session.interfaces.SessionContainer" href="#supertokens_python.recipe.session.interfaces.SessionContainer">SessionContainer</a>]</span>
1287+
<span>async def <span class="ident">get_session</span></span>(<span>self, access_token: Optional[str], anti_csrf_token: Optional[str] = None, anti_csrf_check: Optional[bool] = None, session_required: Optional[bool] = None, check_database: Optional[bool] = None, override_global_claim_validators: Optional[Callable[[List[<a title="supertokens_python.recipe.session.interfaces.SessionClaimValidator" href="#supertokens_python.recipe.session.interfaces.SessionClaimValidator">SessionClaimValidator</a>], <a title="supertokens_python.recipe.session.interfaces.SessionContainer" href="#supertokens_python.recipe.session.interfaces.SessionContainer">SessionContainer</a>, Dict[str, Any]], MaybeAwaitable[List[<a title="supertokens_python.recipe.session.interfaces.SessionClaimValidator" href="#supertokens_python.recipe.session.interfaces.SessionClaimValidator">SessionClaimValidator</a>]]]] = None, user_context: Optional[Dict[str, Any]] = None) ‑> Optional[<a title="supertokens_python.recipe.session.interfaces.SessionContainer" href="#supertokens_python.recipe.session.interfaces.SessionContainer">SessionContainer</a>]</span>
12881288
</code></dt>
12891289
<dd>
12901290
<div class="desc"></div>
@@ -1295,8 +1295,8 @@ <h3>Methods</h3>
12951295
<pre><code class="python">@abstractmethod
12961296
async def get_session(
12971297
self,
1298-
access_token: str,
1299-
anti_csrf_token: Optional[str],
1298+
access_token: Optional[str],
1299+
anti_csrf_token: Optional[str] = None,
13001300
anti_csrf_check: Optional[bool] = None,
13011301
session_required: Optional[bool] = None,
13021302
check_database: Optional[bool] = None,

html/supertokens_python/recipe/session/recipe_implementation.html

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ <h1 class="title">Module <code>supertokens_python.recipe.session.recipe_implemen
199199

200200
async def get_session(
201201
self,
202-
access_token: str,
203-
anti_csrf_token: Optional[str],
202+
access_token: Optional[str],
203+
anti_csrf_token: Optional[str] = None,
204204
anti_csrf_check: Optional[bool] = None,
205205
session_required: Optional[bool] = None,
206206
check_database: Optional[bool] = None,
@@ -222,6 +222,23 @@ <h1 class="title">Module <code>supertokens_python.recipe.session.recipe_implemen
222222

223223
log_debug_message(&#34;getSession: Started&#34;)
224224

225+
if access_token is None:
226+
if session_required is False:
227+
log_debug_message(
228+
&#34;getSession: returning None because access_token is undefined and session_required is False&#34;
229+
)
230+
# there is no session that exists here, and the user wants session verification to be optional. So we return None
231+
return None
232+
233+
log_debug_message(
234+
&#34;getSession: UNAUTHORISED because accessToken in request is undefined&#34;
235+
)
236+
# we do not clear the session here because of a race condition mentioned in https://github.com/supertokens/supertokens-node/issues/17
237+
raise UnauthorisedError(
238+
&#34;Session does not exist. Are you sending the session tokens in the request with the appropriate token transfer method?&#34;,
239+
clear_tokens=False,
240+
)
241+
225242
access_token_obj: Optional[ParsedJWTInfo] = None
226243
try:
227244
access_token_obj = parse_jwt_without_signature_verification(access_token)
@@ -621,8 +638,8 @@ <h2 class="section-title" id="header-classes">Classes</h2>
621638

622639
async def get_session(
623640
self,
624-
access_token: str,
625-
anti_csrf_token: Optional[str],
641+
access_token: Optional[str],
642+
anti_csrf_token: Optional[str] = None,
626643
anti_csrf_check: Optional[bool] = None,
627644
session_required: Optional[bool] = None,
628645
check_database: Optional[bool] = None,
@@ -644,6 +661,23 @@ <h2 class="section-title" id="header-classes">Classes</h2>
644661

645662
log_debug_message(&#34;getSession: Started&#34;)
646663

664+
if access_token is None:
665+
if session_required is False:
666+
log_debug_message(
667+
&#34;getSession: returning None because access_token is undefined and session_required is False&#34;
668+
)
669+
# there is no session that exists here, and the user wants session verification to be optional. So we return None
670+
return None
671+
672+
log_debug_message(
673+
&#34;getSession: UNAUTHORISED because accessToken in request is undefined&#34;
674+
)
675+
# we do not clear the session here because of a race condition mentioned in https://github.com/supertokens/supertokens-node/issues/17
676+
raise UnauthorisedError(
677+
&#34;Session does not exist. Are you sending the session tokens in the request with the appropriate token transfer method?&#34;,
678+
clear_tokens=False,
679+
)
680+
647681
access_token_obj: Optional[ParsedJWTInfo] = None
648682
try:
649683
access_token_obj = parse_jwt_without_signature_verification(access_token)
@@ -1055,7 +1089,7 @@ <h3>Methods</h3>
10551089
</details>
10561090
</dd>
10571091
<dt id="supertokens_python.recipe.session.recipe_implementation.RecipeImplementation.get_session"><code class="name flex">
1058-
<span>async def <span class="ident">get_session</span></span>(<span>self, access_token: str, anti_csrf_token: Optional[str], anti_csrf_check: Optional[bool] = None, session_required: Optional[bool] = None, check_database: Optional[bool] = None, override_global_claim_validators: Optional[Callable[[List[SessionClaimValidator], SessionContainer, Dict[str, Any]], MaybeAwaitable[List[SessionClaimValidator]]]] = None, user_context: Optional[Dict[str, Any]] = None) ‑> Optional[SessionContainer]</span>
1092+
<span>async def <span class="ident">get_session</span></span>(<span>self, access_token: Optional[str], anti_csrf_token: Optional[str] = None, anti_csrf_check: Optional[bool] = None, session_required: Optional[bool] = None, check_database: Optional[bool] = None, override_global_claim_validators: Optional[Callable[[List[SessionClaimValidator], SessionContainer, Dict[str, Any]], MaybeAwaitable[List[SessionClaimValidator]]]] = None, user_context: Optional[Dict[str, Any]] = None) ‑> Optional[SessionContainer]</span>
10591093
</code></dt>
10601094
<dd>
10611095
<div class="desc"></div>
@@ -1065,8 +1099,8 @@ <h3>Methods</h3>
10651099
</summary>
10661100
<pre><code class="python">async def get_session(
10671101
self,
1068-
access_token: str,
1069-
anti_csrf_token: Optional[str],
1102+
access_token: Optional[str],
1103+
anti_csrf_token: Optional[str] = None,
10701104
anti_csrf_check: Optional[bool] = None,
10711105
session_required: Optional[bool] = None,
10721106
check_database: Optional[bool] = None,
@@ -1088,6 +1122,23 @@ <h3>Methods</h3>
10881122

10891123
log_debug_message(&#34;getSession: Started&#34;)
10901124

1125+
if access_token is None:
1126+
if session_required is False:
1127+
log_debug_message(
1128+
&#34;getSession: returning None because access_token is undefined and session_required is False&#34;
1129+
)
1130+
# there is no session that exists here, and the user wants session verification to be optional. So we return None
1131+
return None
1132+
1133+
log_debug_message(
1134+
&#34;getSession: UNAUTHORISED because accessToken in request is undefined&#34;
1135+
)
1136+
# we do not clear the session here because of a race condition mentioned in https://github.com/supertokens/supertokens-node/issues/17
1137+
raise UnauthorisedError(
1138+
&#34;Session does not exist. Are you sending the session tokens in the request with the appropriate token transfer method?&#34;,
1139+
clear_tokens=False,
1140+
)
1141+
10911142
access_token_obj: Optional[ParsedJWTInfo] = None
10921143
try:
10931144
access_token_obj = parse_jwt_without_signature_verification(access_token)

html/supertokens_python/recipe/session/session_request_functions.html

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ <h1 class="title">Module <code>supertokens_python.recipe.session.session_request
155155
allowed_transfer_method = config.get_token_transfer_method(
156156
request, False, user_context
157157
)
158-
request_transfer_method: TokenTransferMethod
159-
request_access_token: Union[ParsedJWTInfo, None]
158+
request_transfer_method: Optional[TokenTransferMethod] = None
159+
request_access_token: Union[ParsedJWTInfo, None] = None
160160

161161
if (allowed_transfer_method in (&#34;any&#34;, &#34;header&#34;)) and access_tokens.get(
162162
&#34;header&#34;
@@ -170,25 +170,6 @@ <h1 class="title">Module <code>supertokens_python.recipe.session.session_request
170170
log_debug_message(&#34;getSession: using cookie transfer method&#34;)
171171
request_transfer_method = &#34;cookie&#34;
172172
request_access_token = access_tokens[&#34;cookie&#34;]
173-
else:
174-
if session_optional:
175-
log_debug_message(
176-
&#34;getSession: returning None because accessToken is undefined and sessionRequired is false&#34;
177-
)
178-
# there is no session that exists here, and the user wants session verification
179-
# to be optional. So we return None
180-
return None
181-
182-
log_debug_message(
183-
&#34;getSession: UNAUTHORISED because access_token in request is None&#34;
184-
)
185-
# we do not clear the session here because of a race condition mentioned in:
186-
# https://github.com/supertokens/supertokens-node/issues/17
187-
raise_unauthorised_exception(
188-
&#34;Session does not exist. Are you sending the session tokens in the &#34;
189-
&#34;request with the appropriate token transfer method?&#34;,
190-
clear_tokens=False,
191-
)
192173

193174
anti_csrf_token = get_anti_csrf_header(request)
194175
do_anti_csrf_check = anti_csrf_check
@@ -214,7 +195,9 @@ <h1 class="title">Module <code>supertokens_python.recipe.session.session_request
214195
log_debug_message(&#34;getSession: Value of antiCsrfToken is: %s&#34;, do_anti_csrf_check)
215196

216197
session = await recipe_interface_impl.get_session(
217-
access_token=request_access_token.raw_token_string,
198+
access_token=request_access_token.raw_token_string
199+
if request_access_token is not None
200+
else None,
218201
anti_csrf_token=anti_csrf_token,
219202
anti_csrf_check=do_anti_csrf_check,
220203
check_database=check_database,
@@ -228,9 +211,22 @@ <h1 class="title">Module <code>supertokens_python.recipe.session.session_request
228211
)
229212
await session.assert_claims(claim_validators, user_context)
230213

214+
# request_transfer_method can only be None here if the user overriddes get_session
215+
# to load the session by a custom method in that (very niche) case they also need to
216+
# override how the session is attached to the response.
217+
# In that scenario the transferMethod passed to attachToRequestResponse likely doesn&#39;t
218+
# matter, still, we follow the general fallback logic
219+
220+
if request_transfer_method is not None:
221+
final_transfer_method = request_transfer_method
222+
elif allowed_transfer_method != &#34;any&#34;:
223+
final_transfer_method = allowed_transfer_method
224+
else:
225+
final_transfer_method = &#34;header&#34;
226+
231227
await session.attach_to_request_response(
232228
request,
233-
request_transfer_method,
229+
final_transfer_method,
234230
)
235231

236232
return session
@@ -665,8 +661,8 @@ <h2 class="section-title" id="header-functions">Functions</h2>
665661
allowed_transfer_method = config.get_token_transfer_method(
666662
request, False, user_context
667663
)
668-
request_transfer_method: TokenTransferMethod
669-
request_access_token: Union[ParsedJWTInfo, None]
664+
request_transfer_method: Optional[TokenTransferMethod] = None
665+
request_access_token: Union[ParsedJWTInfo, None] = None
670666

671667
if (allowed_transfer_method in (&#34;any&#34;, &#34;header&#34;)) and access_tokens.get(
672668
&#34;header&#34;
@@ -680,25 +676,6 @@ <h2 class="section-title" id="header-functions">Functions</h2>
680676
log_debug_message(&#34;getSession: using cookie transfer method&#34;)
681677
request_transfer_method = &#34;cookie&#34;
682678
request_access_token = access_tokens[&#34;cookie&#34;]
683-
else:
684-
if session_optional:
685-
log_debug_message(
686-
&#34;getSession: returning None because accessToken is undefined and sessionRequired is false&#34;
687-
)
688-
# there is no session that exists here, and the user wants session verification
689-
# to be optional. So we return None
690-
return None
691-
692-
log_debug_message(
693-
&#34;getSession: UNAUTHORISED because access_token in request is None&#34;
694-
)
695-
# we do not clear the session here because of a race condition mentioned in:
696-
# https://github.com/supertokens/supertokens-node/issues/17
697-
raise_unauthorised_exception(
698-
&#34;Session does not exist. Are you sending the session tokens in the &#34;
699-
&#34;request with the appropriate token transfer method?&#34;,
700-
clear_tokens=False,
701-
)
702679

703680
anti_csrf_token = get_anti_csrf_header(request)
704681
do_anti_csrf_check = anti_csrf_check
@@ -724,7 +701,9 @@ <h2 class="section-title" id="header-functions">Functions</h2>
724701
log_debug_message(&#34;getSession: Value of antiCsrfToken is: %s&#34;, do_anti_csrf_check)
725702

726703
session = await recipe_interface_impl.get_session(
727-
access_token=request_access_token.raw_token_string,
704+
access_token=request_access_token.raw_token_string
705+
if request_access_token is not None
706+
else None,
728707
anti_csrf_token=anti_csrf_token,
729708
anti_csrf_check=do_anti_csrf_check,
730709
check_database=check_database,
@@ -738,9 +717,22 @@ <h2 class="section-title" id="header-functions">Functions</h2>
738717
)
739718
await session.assert_claims(claim_validators, user_context)
740719

720+
# request_transfer_method can only be None here if the user overriddes get_session
721+
# to load the session by a custom method in that (very niche) case they also need to
722+
# override how the session is attached to the response.
723+
# In that scenario the transferMethod passed to attachToRequestResponse likely doesn&#39;t
724+
# matter, still, we follow the general fallback logic
725+
726+
if request_transfer_method is not None:
727+
final_transfer_method = request_transfer_method
728+
elif allowed_transfer_method != &#34;any&#34;:
729+
final_transfer_method = allowed_transfer_method
730+
else:
731+
final_transfer_method = &#34;header&#34;
732+
741733
await session.attach_to_request_response(
742734
request,
743-
request_transfer_method,
735+
final_transfer_method,
744736
)
745737

746738
return session</code></pre>

0 commit comments

Comments
 (0)