Skip to content

Commit 550c126

Browse files
committed
adding dev-v0.12.2 tag to this commit to ensure building
1 parent 6e982fc commit 550c126

File tree

6 files changed

+148
-108
lines changed

6 files changed

+148
-108
lines changed

html/supertokens_python/constants.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <h1 class="title">Module <code>supertokens_python.constants</code></h1>
4040
# License for the specific language governing permissions and limitations
4141
# under the License.
4242
SUPPORTED_CDI_VERSIONS = [&#34;2.9&#34;, &#34;2.10&#34;, &#34;2.11&#34;, &#34;2.12&#34;, &#34;2.13&#34;, &#34;2.14&#34;, &#34;2.15&#34;]
43-
VERSION = &#34;0.12.1&#34;
43+
VERSION = &#34;0.12.2&#34;
4444
TELEMETRY = &#34;/telemetry&#34;
4545
USER_COUNT = &#34;/users/count&#34;
4646
USER_DELETE = &#34;/user/remove&#34;

html/supertokens_python/framework/fastapi/fastapi_request.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ <h1 class="title">Module <code>supertokens_python.framework.fastapi.fastapi_requ
7373
return self.request.method
7474

7575
def get_cookie(self, key: str) -&gt; Union[str, None]:
76+
# Note: Unlike other frameworks, FastAPI wraps the value in quotes in Set-Cookie header
77+
# It also takes care of escaping the quotes while fetching the value
7678
return self.request.cookies.get(key)
7779

7880
def get_header(self, key: str) -&gt; Union[str, None]:
@@ -141,6 +143,8 @@ <h2 class="section-title" id="header-classes">Classes</h2>
141143
return self.request.method
142144

143145
def get_cookie(self, key: str) -&gt; Union[str, None]:
146+
# Note: Unlike other frameworks, FastAPI wraps the value in quotes in Set-Cookie header
147+
# It also takes care of escaping the quotes while fetching the value
144148
return self.request.cookies.get(key)
145149

146150
def get_header(self, key: str) -&gt; Union[str, None]:
@@ -203,6 +207,8 @@ <h3>Methods</h3>
203207
<span>Expand source code</span>
204208
</summary>
205209
<pre><code class="python">def get_cookie(self, key: str) -&gt; Union[str, None]:
210+
# Note: Unlike other frameworks, FastAPI wraps the value in quotes in Set-Cookie header
211+
# It also takes care of escaping the quotes while fetching the value
206212
return self.request.cookies.get(key)</code></pre>
207213
</details>
208214
</dd>

html/supertokens_python/framework/fastapi/fastapi_response.html

Lines changed: 49 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ <h1 class="title">Module <code>supertokens_python.framework.fastapi.fastapi_resp
4141
# under the License.
4242
import json
4343
from math import ceil
44-
from time import time
4544
from typing import Any, Dict, Optional
4645

4746
from supertokens_python.framework.response import BaseResponse
47+
from supertokens_python.utils import get_timestamp_ms
4848

4949

5050
class FastApiResponse(BaseResponse):
@@ -77,31 +77,22 @@ <h1 class="title">Module <code>supertokens_python.framework.fastapi.fastapi_resp
7777
httponly: bool = False,
7878
samesite: str = &#34;lax&#34;,
7979
):
80-
if domain is None:
81-
# we do ceil because if we do floor, we tests may fail where the access
82-
# token lifetime is set to 1 second
83-
self.response.set_cookie(
84-
key=key,
85-
value=value,
86-
expires=ceil((expires - int(time() * 1000)) / 1000),
87-
path=path,
88-
secure=secure,
89-
httponly=httponly,
90-
samesite=samesite,
91-
)
92-
else:
93-
# we do ceil because if we do floor, we tests may fail where the access
94-
# token lifetime is set to 1 second
95-
self.response.set_cookie(
96-
key=key,
97-
value=value,
98-
expires=ceil((expires - int(time() * 1000)) / 1000),
99-
path=path,
100-
domain=domain,
101-
secure=secure,
102-
httponly=httponly,
103-
samesite=samesite,
104-
)
80+
# Note: For FastAPI response object, the expires value
81+
# doesn&#39;t mean the absolute time in ms, but the duration in seconds
82+
# So we need to convert our absolute expiry time (ms) to a duration (seconds)
83+
84+
# we do ceil because if we do floor, we tests may fail where the access
85+
# token lifetime is set to 1 second
86+
self.response.set_cookie(
87+
key=key,
88+
value=value, # Note: Unlike other frameworks, FastAPI wraps the value in quotes in Set-Cookie header
89+
expires=ceil((expires - get_timestamp_ms()) / 1000),
90+
path=path,
91+
domain=domain, # type: ignore # starlette didn&#39;t set domain as optional type but their default value is None anyways
92+
secure=secure,
93+
httponly=httponly,
94+
samesite=samesite,
95+
)
10596

10697
def set_header(self, key: str, value: str):
10798
self.response.headers[key] = value
@@ -183,31 +174,22 @@ <h2 class="section-title" id="header-classes">Classes</h2>
183174
httponly: bool = False,
184175
samesite: str = &#34;lax&#34;,
185176
):
186-
if domain is None:
187-
# we do ceil because if we do floor, we tests may fail where the access
188-
# token lifetime is set to 1 second
189-
self.response.set_cookie(
190-
key=key,
191-
value=value,
192-
expires=ceil((expires - int(time() * 1000)) / 1000),
193-
path=path,
194-
secure=secure,
195-
httponly=httponly,
196-
samesite=samesite,
197-
)
198-
else:
199-
# we do ceil because if we do floor, we tests may fail where the access
200-
# token lifetime is set to 1 second
201-
self.response.set_cookie(
202-
key=key,
203-
value=value,
204-
expires=ceil((expires - int(time() * 1000)) / 1000),
205-
path=path,
206-
domain=domain,
207-
secure=secure,
208-
httponly=httponly,
209-
samesite=samesite,
210-
)
177+
# Note: For FastAPI response object, the expires value
178+
# doesn&#39;t mean the absolute time in ms, but the duration in seconds
179+
# So we need to convert our absolute expiry time (ms) to a duration (seconds)
180+
181+
# we do ceil because if we do floor, we tests may fail where the access
182+
# token lifetime is set to 1 second
183+
self.response.set_cookie(
184+
key=key,
185+
value=value, # Note: Unlike other frameworks, FastAPI wraps the value in quotes in Set-Cookie header
186+
expires=ceil((expires - get_timestamp_ms()) / 1000),
187+
path=path,
188+
domain=domain, # type: ignore # starlette didn&#39;t set domain as optional type but their default value is None anyways
189+
secure=secure,
190+
httponly=httponly,
191+
samesite=samesite,
192+
)
211193

212194
def set_header(self, key: str, value: str):
213195
self.response.headers[key] = value
@@ -298,31 +280,22 @@ <h3>Methods</h3>
298280
httponly: bool = False,
299281
samesite: str = &#34;lax&#34;,
300282
):
301-
if domain is None:
302-
# we do ceil because if we do floor, we tests may fail where the access
303-
# token lifetime is set to 1 second
304-
self.response.set_cookie(
305-
key=key,
306-
value=value,
307-
expires=ceil((expires - int(time() * 1000)) / 1000),
308-
path=path,
309-
secure=secure,
310-
httponly=httponly,
311-
samesite=samesite,
312-
)
313-
else:
314-
# we do ceil because if we do floor, we tests may fail where the access
315-
# token lifetime is set to 1 second
316-
self.response.set_cookie(
317-
key=key,
318-
value=value,
319-
expires=ceil((expires - int(time() * 1000)) / 1000),
320-
path=path,
321-
domain=domain,
322-
secure=secure,
323-
httponly=httponly,
324-
samesite=samesite,
325-
)</code></pre>
283+
# Note: For FastAPI response object, the expires value
284+
# doesn&#39;t mean the absolute time in ms, but the duration in seconds
285+
# So we need to convert our absolute expiry time (ms) to a duration (seconds)
286+
287+
# we do ceil because if we do floor, we tests may fail where the access
288+
# token lifetime is set to 1 second
289+
self.response.set_cookie(
290+
key=key,
291+
value=value, # Note: Unlike other frameworks, FastAPI wraps the value in quotes in Set-Cookie header
292+
expires=ceil((expires - get_timestamp_ms()) / 1000),
293+
path=path,
294+
domain=domain, # type: ignore # starlette didn&#39;t set domain as optional type but their default value is None anyways
295+
secure=secure,
296+
httponly=httponly,
297+
samesite=samesite,
298+
)</code></pre>
326299
</details>
327300
</dd>
328301
<dt id="supertokens_python.framework.fastapi.fastapi_response.FastApiResponse.set_header"><code class="name flex">

0 commit comments

Comments
 (0)