Skip to content

Commit 7fb96c3

Browse files
committed
feat: Use standard jwt lib for access token v3
1 parent 9fefd8f commit 7fb96c3

19 files changed

+307
-310
lines changed

supertokens_python/querier.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,25 @@ async def f(url: str) -> Response:
197197

198198
return await self.__send_request_helper(path, "PUT", f, len(self.__hosts))
199199

200+
def get_all_core_urls_for_path(self, path: str) -> List[str]:
201+
if self.__hosts is None:
202+
return []
203+
204+
normalized_path = NormalisedURLPath(path)
205+
206+
result: List[str] = []
207+
208+
for h in self.__hosts:
209+
current_domain = h.domain.get_as_string_dangerous()
210+
current_base_path = h.base_path.get_as_string_dangerous()
211+
212+
result.append(
213+
current_domain
214+
+ current_base_path
215+
+ normalized_path.get_as_string_dangerous()
216+
)
217+
return result
218+
200219
async def __send_request_helper(
201220
self,
202221
path: NormalisedURLPath,

supertokens_python/recipe/jwt/api/jwks_get.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ async def jwks_get(api_implementation: APIInterface, api_options: APIOptions):
2323
user_context = default_user_context(api_options.request)
2424

2525
result = await api_implementation.jwks_get(api_options, user_context)
26+
2627
if isinstance(result, JWKSGetResponse):
2728
api_options.response.set_header("Access-Control-Allow-Origin", "*")
29+
2830
return send_200_response(result.to_json(), api_options.response)

supertokens_python/recipe/jwt/asyncio/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from typing import Any, Dict, Union
14+
from typing import Any, Dict, Union, Optional
1515

1616
from supertokens_python.recipe.jwt.interfaces import (
1717
CreateJwtOkResult,
@@ -22,21 +22,22 @@
2222

2323

2424
async def create_jwt(
25-
payload: Union[None, Dict[str, Any]] = None,
26-
validity_seconds: Union[None, int] = None,
27-
user_context: Union[Dict[str, Any], None] = None,
25+
payload: Optional[Dict[str, Any]] = None,
26+
validity_seconds: Optional[int] = None,
27+
use_static_signing_key: Optional[bool] = None,
28+
user_context: Optional[Dict[str, Any]] = None,
2829
) -> Union[CreateJwtOkResult, CreateJwtResultUnsupportedAlgorithm]:
2930
if user_context is None:
3031
user_context = {}
3132
if payload is None:
3233
payload = {}
3334

3435
return await JWTRecipe.get_instance().recipe_implementation.create_jwt(
35-
payload, validity_seconds, user_context
36+
payload, validity_seconds, use_static_signing_key, user_context
3637
)
3738

3839

39-
async def get_jwks(user_context: Union[Dict[str, Any], None] = None) -> GetJWKSResult:
40+
async def get_jwks(user_context: Optional[Dict[str, Any]] = None) -> GetJWKSResult:
4041
if user_context is None:
4142
user_context = {}
4243
return await JWTRecipe.get_instance().recipe_implementation.get_jwks(user_context)

supertokens_python/recipe/jwt/interfaces.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414
from abc import ABC, abstractmethod
15-
from typing import Any, Dict, List, Union
15+
from typing import Any, Dict, List, Union, Optional
1616

1717
from supertokens_python.framework import BaseRequest, BaseResponse
1818
from supertokens_python.types import APIResponse, GeneralErrorResponse
@@ -52,7 +52,8 @@ def __init__(self):
5252
async def create_jwt(
5353
self,
5454
payload: Dict[str, Any],
55-
validity_seconds: Union[int, None],
55+
validity_seconds: Optional[int],
56+
use_static_signing_key: Optional[bool],
5657
user_context: Dict[str, Any],
5758
) -> Union[CreateJwtOkResult, CreateJwtResultUnsupportedAlgorithm]:
5859
pass
@@ -79,8 +80,6 @@ def __init__(
7980

8081

8182
class JWKSGetResponse(APIResponse):
82-
status: str = "OK"
83-
8483
def __init__(self, keys: List[JsonWebKey]):
8584
self.keys = keys
8685

@@ -98,7 +97,7 @@ def to_json(self) -> Dict[str, Any]:
9897
}
9998
)
10099

101-
return {"status": self.status, "keys": keys}
100+
return {"keys": keys}
102101

103102

104103
class APIInterface:

supertokens_python/recipe/jwt/recipe_implementation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# under the License.
1414
from __future__ import annotations
1515

16-
from typing import TYPE_CHECKING, Any, Dict, List, Union
16+
from typing import TYPE_CHECKING, Any, Dict, List, Union, Optional
1717

1818
from supertokens_python.normalised_url_path import NormalisedURLPath
1919
from supertokens_python.querier import Querier
@@ -42,7 +42,8 @@ def __init__(self, querier: Querier, config: JWTConfig, app_info: AppInfo):
4242
async def create_jwt(
4343
self,
4444
payload: Dict[str, Any],
45-
validity_seconds: Union[int, None],
45+
validity_seconds: Optional[int],
46+
use_static_signing_key: Optional[bool],
4647
user_context: Dict[str, Any],
4748
) -> Union[CreateJwtOkResult, CreateJwtResultUnsupportedAlgorithm]:
4849
if validity_seconds is None:
@@ -51,6 +52,7 @@ async def create_jwt(
5152
data = {
5253
"payload": payload,
5354
"validity": validity_seconds,
55+
"use_static_signing_key": use_static_signing_key is not False,
5456
"algorithm": "RS256",
5557
"jwksDomain": self.app_info.api_domain.get_as_string_dangerous(),
5658
}
@@ -64,7 +66,7 @@ async def create_jwt(
6466

6567
async def get_jwks(self, user_context: Dict[str, Any]) -> GetJWKSResult:
6668
response = await self.querier.send_get_request(
67-
NormalisedURLPath("/recipe/jwt/jwks"), {}
69+
NormalisedURLPath("/.well-known/jwks.json"), {}
6870
)
6971

7072
keys: List[JsonWebKey] = []

supertokens_python/recipe/jwt/syncio/__init__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from typing import Any, Dict, Union
14+
from typing import Any, Dict, Union, Optional
1515

1616
from supertokens_python.async_to_sync_wrapper import sync
1717
from supertokens_python.recipe.jwt import asyncio
@@ -23,12 +23,17 @@
2323

2424

2525
def create_jwt(
26-
payload: Union[None, Dict[str, Any]] = None,
27-
validity_seconds: Union[None, int] = None,
28-
user_context: Union[Dict[str, Any], None] = None,
26+
payload: Optional[Dict[str, Any]] = None,
27+
validity_seconds: Optional[int] = None,
28+
use_static_signing_key: Optional[bool] = None,
29+
user_context: Optional[Dict[str, Any]] = None,
2930
) -> Union[CreateJwtOkResult, CreateJwtResultUnsupportedAlgorithm]:
30-
return sync(asyncio.create_jwt(payload, validity_seconds, user_context))
31+
return sync(
32+
asyncio.create_jwt(
33+
payload, validity_seconds, use_static_signing_key, user_context
34+
)
35+
)
3136

3237

33-
def get_jwks(user_context: Union[Dict[str, Any], None] = None) -> GetJWKSResult:
38+
def get_jwks(user_context: Optional[Dict[str, Any]] = None) -> GetJWKSResult:
3439
return sync(asyncio.get_jwks(user_context))

supertokens_python/recipe/openid/asyncio/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from typing import Any, Dict, Union
14+
from typing import Any, Dict, Union, Optional
1515

1616
from supertokens_python.recipe.openid.interfaces import (
1717
GetOpenIdDiscoveryConfigurationResult,
@@ -26,21 +26,22 @@
2626

2727

2828
async def create_jwt(
29-
payload: Union[None, Dict[str, Any]] = None,
30-
validity_seconds: Union[None, int] = None,
31-
user_context: Union[Dict[str, Any], None] = None,
29+
payload: Optional[Dict[str, Any]] = None,
30+
validity_seconds: Optional[int] = None,
31+
use_static_signing_key: Optional[bool] = None,
32+
user_context: Optional[Dict[str, Any]] = None,
3233
) -> Union[CreateJwtOkResult, CreateJwtResultUnsupportedAlgorithm]:
3334
if user_context is None:
3435
user_context = {}
3536
if payload is None:
3637
payload = {}
3738

3839
return await OpenIdRecipe.get_instance().recipe_implementation.create_jwt(
39-
payload, validity_seconds, user_context
40+
payload, validity_seconds, use_static_signing_key, user_context
4041
)
4142

4243

43-
async def get_jwks(user_context: Union[Dict[str, Any], None] = None) -> GetJWKSResult:
44+
async def get_jwks(user_context: Optional[Dict[str, Any]] = None) -> GetJWKSResult:
4445
if user_context is None:
4546
user_context = {}
4647
return await OpenIdRecipe.get_instance().recipe_implementation.get_jwks(
@@ -49,7 +50,7 @@ async def get_jwks(user_context: Union[Dict[str, Any], None] = None) -> GetJWKSR
4950

5051

5152
async def get_open_id_discovery_configuration(
52-
user_context: Union[Dict[str, Any], None] = None
53+
user_context: Optional[Dict[str, Any]] = None
5354
) -> GetOpenIdDiscoveryConfigurationResult:
5455
if user_context is None:
5556
user_context = {}

supertokens_python/recipe/openid/interfaces.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414
from abc import ABC, abstractmethod
15-
from typing import Any, Dict, Union
15+
from typing import Any, Dict, Union, Optional
1616

1717
from supertokens_python.framework import BaseRequest, BaseResponse
1818
from supertokens_python.recipe.jwt.interfaces import (
@@ -39,7 +39,8 @@ def __init__(self):
3939
async def create_jwt(
4040
self,
4141
payload: Dict[str, Any],
42-
validity_seconds: Union[int, None],
42+
validity_seconds: Optional[int],
43+
use_static_signing_key: Optional[bool],
4344
user_context: Dict[str, Any],
4445
) -> Union[CreateJwtOkResult, CreateJwtResultUnsupportedAlgorithm]:
4546
pass

supertokens_python/recipe/openid/recipe_implementation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# under the License.
1414
from __future__ import annotations
1515

16-
from typing import TYPE_CHECKING, Any, Dict, Union
16+
from typing import TYPE_CHECKING, Any, Dict, Union, Optional
1717

1818
from supertokens_python.querier import Querier
1919

@@ -69,7 +69,8 @@ def __init__(
6969
async def create_jwt(
7070
self,
7171
payload: Dict[str, Any],
72-
validity_seconds: Union[int, None],
72+
validity_seconds: Optional[int],
73+
use_static_signing_key: Optional[bool],
7374
user_context: Dict[str, Any],
7475
) -> Union[CreateJwtOkResult, CreateJwtResultUnsupportedAlgorithm]:
7576
issuer = (
@@ -78,7 +79,7 @@ async def create_jwt(
7879
)
7980
payload = {"iss": issuer, **payload}
8081
return await self.jwt_recipe_implementation.create_jwt(
81-
payload, validity_seconds, user_context
82+
payload, validity_seconds, use_static_signing_key, user_context
8283
)
8384

8485
async def get_jwks(self, user_context: Dict[str, Any]) -> GetJWKSResult:

supertokens_python/recipe/openid/syncio/__init__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from typing import Any, Dict, Union
14+
from typing import Any, Dict, Union, Optional
1515

1616
from supertokens_python.async_to_sync_wrapper import sync
1717
from supertokens_python.recipe.openid import asyncio
@@ -27,18 +27,23 @@
2727

2828

2929
def create_jwt(
30-
payload: Union[None, Dict[str, Any]] = None,
31-
validity_seconds: Union[None, int] = None,
32-
user_context: Union[Dict[str, Any], None] = None,
30+
payload: Optional[Dict[str, Any]] = None,
31+
validity_seconds: Optional[int] = None,
32+
use_static_signing_key: Optional[bool] = None,
33+
user_context: Optional[Dict[str, Any]] = None,
3334
) -> Union[CreateJwtOkResult, CreateJwtResultUnsupportedAlgorithm]:
34-
return sync(asyncio.create_jwt(payload, validity_seconds, user_context))
35+
return sync(
36+
asyncio.create_jwt(
37+
payload, validity_seconds, use_static_signing_key, user_context
38+
)
39+
)
3540

3641

37-
def get_jwks(user_context: Union[Dict[str, Any], None] = None) -> GetJWKSResult:
42+
def get_jwks(user_context: Optional[Dict[str, Any]] = None) -> GetJWKSResult:
3843
return sync(asyncio.get_jwks(user_context))
3944

4045

4146
def get_open_id_discovery_configuration(
42-
user_context: Union[Dict[str, Any], None] = None
47+
user_context: Optional[Dict[str, Any]] = None
4348
) -> GetOpenIdDiscoveryConfigurationResult:
4449
return sync(asyncio.get_open_id_discovery_configuration(user_context))

0 commit comments

Comments
 (0)