Skip to content

Commit eae5482

Browse files
committed
adding dev-v0.16.3 tag to this commit to ensure building
1 parent c5478e4 commit eae5482

15 files changed

+561
-83
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;3.0&#34;]
45-
VERSION = &#34;0.16.2&#34;
45+
VERSION = &#34;0.16.3&#34;
4646
TELEMETRY = &#34;/telemetry&#34;
4747
USER_COUNT = &#34;/users/count&#34;
4848
USER_DELETE = &#34;/user/remove&#34;

html/supertokens_python/querier.html

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
188188

189189
async def send_get_request(
190190
self, path: NormalisedURLPath, params: Union[Dict[str, Any], None] = None
191-
):
191+
) -&gt; Dict[str, Any]:
192192
if params is None:
193193
params = {}
194194

@@ -208,7 +208,7 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
208208
path: NormalisedURLPath,
209209
data: Union[Dict[str, Any], None] = None,
210210
test: bool = False,
211-
):
211+
) -&gt; Dict[str, Any]:
212212
if data is None:
213213
data = {}
214214

@@ -235,7 +235,7 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
235235

236236
async def send_delete_request(
237237
self, path: NormalisedURLPath, params: Union[Dict[str, Any], None] = None
238-
):
238+
) -&gt; Dict[str, Any]:
239239
if params is None:
240240
params = {}
241241

@@ -252,7 +252,7 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
252252

253253
async def send_put_request(
254254
self, path: NormalisedURLPath, data: Union[Dict[str, Any], None] = None
255-
):
255+
) -&gt; Dict[str, Any]:
256256
if data is None:
257257
data = {}
258258

@@ -290,7 +290,7 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
290290
http_function: Callable[[str, str], Awaitable[Response]],
291291
no_of_tries: int,
292292
retry_info_map: Optional[Dict[str, int]] = None,
293-
) -&gt; Any:
293+
) -&gt; Dict[str, Any]:
294294
if no_of_tries == 0:
295295
raise_general_exception(&#34;No SuperTokens core available to query&#34;)
296296

@@ -349,10 +349,14 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
349349
+ response.text # type: ignore
350350
)
351351

352+
res: Dict[str, Any] = {&#34;_headers&#34;: dict(response.headers)}
353+
352354
try:
353-
return response.json()
355+
res.update(response.json())
354356
except JSONDecodeError:
355-
return response.text
357+
res[&#34;_text&#34;] = response.text
358+
359+
return res
356360

357361
except (ConnectionError, NetworkError, ConnectTimeout) as _:
358362
return await self.__send_request_helper(
@@ -498,7 +502,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
498502

499503
async def send_get_request(
500504
self, path: NormalisedURLPath, params: Union[Dict[str, Any], None] = None
501-
):
505+
) -&gt; Dict[str, Any]:
502506
if params is None:
503507
params = {}
504508

@@ -518,7 +522,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
518522
path: NormalisedURLPath,
519523
data: Union[Dict[str, Any], None] = None,
520524
test: bool = False,
521-
):
525+
) -&gt; Dict[str, Any]:
522526
if data is None:
523527
data = {}
524528

@@ -545,7 +549,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
545549

546550
async def send_delete_request(
547551
self, path: NormalisedURLPath, params: Union[Dict[str, Any], None] = None
548-
):
552+
) -&gt; Dict[str, Any]:
549553
if params is None:
550554
params = {}
551555

@@ -562,7 +566,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
562566

563567
async def send_put_request(
564568
self, path: NormalisedURLPath, data: Union[Dict[str, Any], None] = None
565-
):
569+
) -&gt; Dict[str, Any]:
566570
if data is None:
567571
data = {}
568572

@@ -600,7 +604,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
600604
http_function: Callable[[str, str], Awaitable[Response]],
601605
no_of_tries: int,
602606
retry_info_map: Optional[Dict[str, int]] = None,
603-
) -&gt; Any:
607+
) -&gt; Dict[str, Any]:
604608
if no_of_tries == 0:
605609
raise_general_exception(&#34;No SuperTokens core available to query&#34;)
606610

@@ -659,10 +663,14 @@ <h2 class="section-title" id="header-classes">Classes</h2>
659663
+ response.text # type: ignore
660664
)
661665

666+
res: Dict[str, Any] = {&#34;_headers&#34;: dict(response.headers)}
667+
662668
try:
663-
return response.json()
669+
res.update(response.json())
664670
except JSONDecodeError:
665-
return response.text
671+
res[&#34;_text&#34;] = response.text
672+
673+
return res
666674

667675
except (ConnectionError, NetworkError, ConnectTimeout) as _:
668676
return await self.__send_request_helper(
@@ -866,7 +874,7 @@ <h3>Methods</h3>
866874
</details>
867875
</dd>
868876
<dt id="supertokens_python.querier.Querier.send_delete_request"><code class="name flex">
869-
<span>async def <span class="ident">send_delete_request</span></span>(<span>self, path: NormalisedURLPath, params: Union[Dict[str, Any], None] = None)</span>
877+
<span>async def <span class="ident">send_delete_request</span></span>(<span>self, path: NormalisedURLPath, params: Union[Dict[str, Any], None] = None)> Dict[str, Any]</span>
870878
</code></dt>
871879
<dd>
872880
<div class="desc"></div>
@@ -876,7 +884,7 @@ <h3>Methods</h3>
876884
</summary>
877885
<pre><code class="python">async def send_delete_request(
878886
self, path: NormalisedURLPath, params: Union[Dict[str, Any], None] = None
879-
):
887+
) -&gt; Dict[str, Any]:
880888
if params is None:
881889
params = {}
882890

@@ -893,7 +901,7 @@ <h3>Methods</h3>
893901
</details>
894902
</dd>
895903
<dt id="supertokens_python.querier.Querier.send_get_request"><code class="name flex">
896-
<span>async def <span class="ident">send_get_request</span></span>(<span>self, path: NormalisedURLPath, params: Union[Dict[str, Any], None] = None)</span>
904+
<span>async def <span class="ident">send_get_request</span></span>(<span>self, path: NormalisedURLPath, params: Union[Dict[str, Any], None] = None)> Dict[str, Any]</span>
897905
</code></dt>
898906
<dd>
899907
<div class="desc"></div>
@@ -903,7 +911,7 @@ <h3>Methods</h3>
903911
</summary>
904912
<pre><code class="python">async def send_get_request(
905913
self, path: NormalisedURLPath, params: Union[Dict[str, Any], None] = None
906-
):
914+
) -&gt; Dict[str, Any]:
907915
if params is None:
908916
params = {}
909917

@@ -920,7 +928,7 @@ <h3>Methods</h3>
920928
</details>
921929
</dd>
922930
<dt id="supertokens_python.querier.Querier.send_post_request"><code class="name flex">
923-
<span>async def <span class="ident">send_post_request</span></span>(<span>self, path: NormalisedURLPath, data: Union[Dict[str, Any], None] = None, test: bool = False)</span>
931+
<span>async def <span class="ident">send_post_request</span></span>(<span>self, path: NormalisedURLPath, data: Union[Dict[str, Any], None] = None, test: bool = False)> Dict[str, Any]</span>
924932
</code></dt>
925933
<dd>
926934
<div class="desc"></div>
@@ -933,7 +941,7 @@ <h3>Methods</h3>
933941
path: NormalisedURLPath,
934942
data: Union[Dict[str, Any], None] = None,
935943
test: bool = False,
936-
):
944+
) -&gt; Dict[str, Any]:
937945
if data is None:
938946
data = {}
939947

@@ -960,7 +968,7 @@ <h3>Methods</h3>
960968
</details>
961969
</dd>
962970
<dt id="supertokens_python.querier.Querier.send_put_request"><code class="name flex">
963-
<span>async def <span class="ident">send_put_request</span></span>(<span>self, path: NormalisedURLPath, data: Union[Dict[str, Any], None] = None)</span>
971+
<span>async def <span class="ident">send_put_request</span></span>(<span>self, path: NormalisedURLPath, data: Union[Dict[str, Any], None] = None)> Dict[str, Any]</span>
964972
</code></dt>
965973
<dd>
966974
<div class="desc"></div>
@@ -970,7 +978,7 @@ <h3>Methods</h3>
970978
</summary>
971979
<pre><code class="python">async def send_put_request(
972980
self, path: NormalisedURLPath, data: Union[Dict[str, Any], None] = None
973-
):
981+
) -&gt; Dict[str, Any]:
974982
if data is None:
975983
data = {}
976984

html/supertokens_python/recipe/jwt/api/implementation.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ <h1 class="title">Module <code>supertokens_python.recipe.jwt.api.implementation<
5353
self, api_options: APIOptions, user_context: Dict[str, Any]
5454
) -&gt; JWKSGetResponse:
5555
response = await api_options.recipe_implementation.get_jwks(user_context)
56+
57+
if response.validity_in_secs is not None:
58+
api_options.response.set_header(
59+
&#34;Cache-Control&#34;, f&#34;max-age={response.validity_in_secs}, must-revalidate&#34;
60+
)
61+
5662
return JWKSGetResponse(response.keys)</code></pre>
5763
</details>
5864
</section>
@@ -79,6 +85,12 @@ <h2 class="section-title" id="header-classes">Classes</h2>
7985
self, api_options: APIOptions, user_context: Dict[str, Any]
8086
) -&gt; JWKSGetResponse:
8187
response = await api_options.recipe_implementation.get_jwks(user_context)
88+
89+
if response.validity_in_secs is not None:
90+
api_options.response.set_header(
91+
&#34;Cache-Control&#34;, f&#34;max-age={response.validity_in_secs}, must-revalidate&#34;
92+
)
93+
8294
return JWKSGetResponse(response.keys)</code></pre>
8395
</details>
8496
<h3>Ancestors</h3>
@@ -100,6 +112,12 @@ <h3>Methods</h3>
100112
self, api_options: APIOptions, user_context: Dict[str, Any]
101113
) -&gt; JWKSGetResponse:
102114
response = await api_options.recipe_implementation.get_jwks(user_context)
115+
116+
if response.validity_in_secs is not None:
117+
api_options.response.set_header(
118+
&#34;Cache-Control&#34;, f&#34;max-age={response.validity_in_secs}, must-revalidate&#34;
119+
)
120+
103121
return JWKSGetResponse(response.keys)</code></pre>
104122
</details>
105123
</dd>

html/supertokens_python/recipe/jwt/interfaces.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ <h1 class="title">Module <code>supertokens_python.recipe.jwt.interfaces</code></
6868

6969

7070
class GetJWKSResult:
71-
def __init__(self, keys: List[JsonWebKey]):
71+
def __init__(self, keys: List[JsonWebKey], validity_in_secs: Optional[int]):
7272
self.keys = keys
73+
self.validity_in_secs = validity_in_secs
7374

7475

7576
class RecipeInterface(ABC):
@@ -247,7 +248,7 @@ <h3>Methods</h3>
247248
</dd>
248249
<dt id="supertokens_python.recipe.jwt.interfaces.GetJWKSResult"><code class="flex name class">
249250
<span>class <span class="ident">GetJWKSResult</span></span>
250-
<span>(</span><span>keys: List[<a title="supertokens_python.recipe.jwt.interfaces.JsonWebKey" href="#supertokens_python.recipe.jwt.interfaces.JsonWebKey">JsonWebKey</a>])</span>
251+
<span>(</span><span>keys: List[<a title="supertokens_python.recipe.jwt.interfaces.JsonWebKey" href="#supertokens_python.recipe.jwt.interfaces.JsonWebKey">JsonWebKey</a>], validity_in_secs: Optional[int])</span>
251252
</code></dt>
252253
<dd>
253254
<div class="desc"></div>
@@ -256,8 +257,9 @@ <h3>Methods</h3>
256257
<span>Expand source code</span>
257258
</summary>
258259
<pre><code class="python">class GetJWKSResult:
259-
def __init__(self, keys: List[JsonWebKey]):
260-
self.keys = keys</code></pre>
260+
def __init__(self, keys: List[JsonWebKey], validity_in_secs: Optional[int]):
261+
self.keys = keys
262+
self.validity_in_secs = validity_in_secs</code></pre>
261263
</details>
262264
</dd>
263265
<dt id="supertokens_python.recipe.jwt.interfaces.JWKSGetResponse"><code class="flex name class">

html/supertokens_python/recipe/jwt/recipe_implementation.html

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ <h1 class="title">Module <code>supertokens_python.recipe.jwt.recipe_implementati
4545

4646
from supertokens_python.normalised_url_path import NormalisedURLPath
4747
from supertokens_python.querier import Querier
48+
import re
4849

4950
if TYPE_CHECKING:
5051
from .utils import JWTConfig
@@ -60,6 +61,10 @@ <h1 class="title">Module <code>supertokens_python.recipe.jwt.recipe_implementati
6061
from .interfaces import JsonWebKey
6162

6263

64+
# This corresponds to the dynamicSigningKeyOverlapMS in the core
65+
DEFAULT_JWKS_MAX_AGE = 60
66+
67+
6368
class RecipeImplementation(RecipeInterface):
6469
def __init__(self, querier: Querier, config: JWTConfig, app_info: AppInfo):
6570
super().__init__()
@@ -97,14 +102,28 @@ <h1 class="title">Module <code>supertokens_python.recipe.jwt.recipe_implementati
97102
NormalisedURLPath(&#34;/.well-known/jwks.json&#34;), {}
98103
)
99104

105+
validity_in_secs = DEFAULT_JWKS_MAX_AGE
106+
cache_control = response[&#34;_headers&#34;].get(&#34;Cache-Control&#34;)
107+
108+
if cache_control is not None:
109+
pattern = r&#34;,?\s*max-age=(\d+)(?:,|$)&#34;
110+
max_age_header = re.match(pattern, cache_control)
111+
if max_age_header is not None:
112+
validity_in_secs = int(max_age_header.group(1))
113+
try:
114+
validity_in_secs = int(validity_in_secs)
115+
except Exception:
116+
validity_in_secs = DEFAULT_JWKS_MAX_AGE
117+
100118
keys: List[JsonWebKey] = []
101119
for key in response[&#34;keys&#34;]:
102120
keys.append(
103121
JsonWebKey(
104122
key[&#34;kty&#34;], key[&#34;kid&#34;], key[&#34;n&#34;], key[&#34;e&#34;], key[&#34;alg&#34;], key[&#34;use&#34;]
105123
)
106124
)
107-
return GetJWKSResult(keys)</code></pre>
125+
126+
return GetJWKSResult(keys, validity_in_secs)</code></pre>
108127
</details>
109128
</section>
110129
<section>
@@ -164,14 +183,28 @@ <h2 class="section-title" id="header-classes">Classes</h2>
164183
NormalisedURLPath(&#34;/.well-known/jwks.json&#34;), {}
165184
)
166185

186+
validity_in_secs = DEFAULT_JWKS_MAX_AGE
187+
cache_control = response[&#34;_headers&#34;].get(&#34;Cache-Control&#34;)
188+
189+
if cache_control is not None:
190+
pattern = r&#34;,?\s*max-age=(\d+)(?:,|$)&#34;
191+
max_age_header = re.match(pattern, cache_control)
192+
if max_age_header is not None:
193+
validity_in_secs = int(max_age_header.group(1))
194+
try:
195+
validity_in_secs = int(validity_in_secs)
196+
except Exception:
197+
validity_in_secs = DEFAULT_JWKS_MAX_AGE
198+
167199
keys: List[JsonWebKey] = []
168200
for key in response[&#34;keys&#34;]:
169201
keys.append(
170202
JsonWebKey(
171203
key[&#34;kty&#34;], key[&#34;kid&#34;], key[&#34;n&#34;], key[&#34;e&#34;], key[&#34;alg&#34;], key[&#34;use&#34;]
172204
)
173205
)
174-
return GetJWKSResult(keys)</code></pre>
206+
207+
return GetJWKSResult(keys, validity_in_secs)</code></pre>
175208
</details>
176209
<h3>Ancestors</h3>
177210
<ul class="hlist">
@@ -229,14 +262,28 @@ <h3>Methods</h3>
229262
NormalisedURLPath(&#34;/.well-known/jwks.json&#34;), {}
230263
)
231264

265+
validity_in_secs = DEFAULT_JWKS_MAX_AGE
266+
cache_control = response[&#34;_headers&#34;].get(&#34;Cache-Control&#34;)
267+
268+
if cache_control is not None:
269+
pattern = r&#34;,?\s*max-age=(\d+)(?:,|$)&#34;
270+
max_age_header = re.match(pattern, cache_control)
271+
if max_age_header is not None:
272+
validity_in_secs = int(max_age_header.group(1))
273+
try:
274+
validity_in_secs = int(validity_in_secs)
275+
except Exception:
276+
validity_in_secs = DEFAULT_JWKS_MAX_AGE
277+
232278
keys: List[JsonWebKey] = []
233279
for key in response[&#34;keys&#34;]:
234280
keys.append(
235281
JsonWebKey(
236282
key[&#34;kty&#34;], key[&#34;kid&#34;], key[&#34;n&#34;], key[&#34;e&#34;], key[&#34;alg&#34;], key[&#34;use&#34;]
237283
)
238284
)
239-
return GetJWKSResult(keys)</code></pre>
285+
286+
return GetJWKSResult(keys, validity_in_secs)</code></pre>
240287
</details>
241288
</dd>
242289
</dl>

0 commit comments

Comments
 (0)