Skip to content

Commit bb515f4

Browse files
committed
changed init function to accept None for api_key
1 parent 1776a53 commit bb515f4

File tree

7 files changed

+122
-80
lines changed

7 files changed

+122
-80
lines changed

supertokens_python/constants.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@
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-
SUPPORTED_CDI_VERSIONS = ["2.9", "2.10", "2.11", "2.12", "2.13", "2.14", "2.15", "2.16", "2.17", "2.18"]
14+
SUPPORTED_CDI_VERSIONS = [
15+
"2.9",
16+
"2.10",
17+
"2.11",
18+
"2.12",
19+
"2.13",
20+
"2.14",
21+
"2.15",
22+
"2.16",
23+
"2.17",
24+
"2.18",
25+
]
1526
VERSION = "0.12.2"
1627
TELEMETRY = "/telemetry"
1728
USER_COUNT = "/users/count"

supertokens_python/recipe/dashboard/api/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
from .userdetails.user_delete import handle_user_delete
1919
from .userdetails.user_email_verify_get import handle_user_email_verify_get
2020
from .userdetails.user_email_verify_put import handle_user_email_verify_put
21-
from .userdetails.user_email_verify_token_post import \
22-
handle_email_verify_token_post
21+
from .userdetails.user_email_verify_token_post import handle_email_verify_token_post
2322
from .userdetails.user_get import handle_user_get
2423
from .userdetails.user_metadata_get import handle_metadata_get
2524
from .userdetails.user_metadata_put import handle_metadata_put
@@ -49,5 +48,5 @@
4948
"handle_user_password_put",
5049
"handle_email_verify_token_post",
5150
"handle_sign_in_api",
52-
"handle_signout"
51+
"handle_signout",
5352
]

supertokens_python/recipe/dashboard/api/signin.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
from typing import TYPE_CHECKING
1717

1818
if TYPE_CHECKING:
19-
from supertokens_python.recipe.dashboard.interfaces import (APIInterface,
20-
APIOptions)
21-
19+
from supertokens_python.recipe.dashboard.interfaces import APIInterface, APIOptions
2220

21+
# pylint: disable=unused-argument
2322
async def handle_sign_in_api(api_implementation: APIInterface, api_options: APIOptions):
24-
pass
23+
pass

supertokens_python/recipe/dashboard/api/signout.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
from typing import TYPE_CHECKING
1717

1818
if TYPE_CHECKING:
19-
from supertokens_python.recipe.dashboard.interfaces import (APIInterface,
20-
APIOptions)
19+
from supertokens_python.recipe.dashboard.interfaces import APIInterface, APIOptions
2120

2221
from ..interfaces import SignOutOK
2322

2423

25-
async def handle_signout(api_implementation: APIInterface, api_options: APIOptions) -> SignOutOK:
26-
pass
24+
# pylint: disable=unused-argument
25+
async def handle_signout(
26+
api_implementation: APIInterface, api_options: APIOptions
27+
) -> SignOutOK:
28+
return SignOutOK()

supertokens_python/recipe/dashboard/interfaces.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
from __future__ import annotations
1515

1616
from abc import ABC, abstractmethod
17-
from typing import (TYPE_CHECKING, Any, Awaitable, Callable, Dict, List,
18-
Optional, Union)
17+
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, List, Optional, Union
1918

20-
from supertokens_python.recipe.session.interfaces import \
21-
SessionInformationResult
19+
from supertokens_python.recipe.session.interfaces import SessionInformationResult
2220
from supertokens_python.types import User
2321

2422
from ...supertokens import AppInfo
@@ -288,6 +286,7 @@ def __init__(self, error: str) -> None:
288286
def to_json(self) -> Dict[str, Any]:
289287
return {"status": self.status, "error": self.error}
290288

289+
291290
class SignOutOK(APIResponse):
292291
def to_json(self):
293-
return {"status": "OK"}
292+
return {"status": "OK"}

supertokens_python/recipe/dashboard/recipe.py

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,26 @@
1919
from supertokens_python.normalised_url_path import NormalisedURLPath
2020
from supertokens_python.recipe_module import APIHandled, RecipeModule
2121

22-
from .api import (api_key_protector, handle_dashboard_api,
23-
handle_email_verify_token_post, handle_metadata_get,
24-
handle_metadata_put, handle_sessions_get, handle_sign_in_api,
25-
handle_signout, handle_user_delete,
26-
handle_user_email_verify_get, handle_user_email_verify_put,
27-
handle_user_get, handle_user_password_put, handle_user_put,
28-
handle_user_sessions_post, handle_users_count_get_api,
29-
handle_users_get_api, handle_validate_key_api)
22+
from .api import (
23+
api_key_protector,
24+
handle_dashboard_api,
25+
handle_email_verify_token_post,
26+
handle_metadata_get,
27+
handle_metadata_put,
28+
handle_sessions_get,
29+
handle_sign_in_api,
30+
handle_signout,
31+
handle_user_delete,
32+
handle_user_email_verify_get,
33+
handle_user_email_verify_put,
34+
handle_user_get,
35+
handle_user_password_put,
36+
handle_user_put,
37+
handle_user_sessions_post,
38+
handle_users_count_get_api,
39+
handle_users_get_api,
40+
handle_validate_key_api,
41+
)
3042
from .api.implementation import APIImplementation
3143
from .exceptions import SuperTokensDashboardError
3244
from .interfaces import APIInterface, APIOptions
@@ -38,16 +50,28 @@
3850
from supertokens_python.supertokens import AppInfo
3951
from supertokens_python.types import APIResponse
4052

41-
from supertokens_python.exceptions import (SuperTokensError,
42-
raise_general_exception)
43-
44-
from .constants import (DASHBOARD_API, EMAIL_PASSSWORD_SIGNOUT,
45-
EMAIL_PASSWORD_SIGN_IN, USER_API,
46-
USER_EMAIL_VERIFY_API, USER_EMAIL_VERIFY_TOKEN_API,
47-
USER_METADATA_API, USER_PASSWORD_API, USER_SESSION_API,
48-
USERS_COUNT_API, USERS_LIST_GET_API, VALIDATE_KEY_API)
49-
from .utils import (InputOverrideConfig, get_api_if_matched, is_api_path,
50-
validate_and_normalise_user_input)
53+
from supertokens_python.exceptions import SuperTokensError, raise_general_exception
54+
55+
from .constants import (
56+
DASHBOARD_API,
57+
EMAIL_PASSSWORD_SIGNOUT,
58+
EMAIL_PASSWORD_SIGN_IN,
59+
USER_API,
60+
USER_EMAIL_VERIFY_API,
61+
USER_EMAIL_VERIFY_TOKEN_API,
62+
USER_METADATA_API,
63+
USER_PASSWORD_API,
64+
USER_SESSION_API,
65+
USERS_COUNT_API,
66+
USERS_LIST_GET_API,
67+
VALIDATE_KEY_API,
68+
)
69+
from .utils import (
70+
InputOverrideConfig,
71+
get_api_if_matched,
72+
is_api_path,
73+
validate_and_normalise_user_input,
74+
)
5175

5276

5377
class DashboardRecipe(RecipeModule):
@@ -58,7 +82,7 @@ def __init__(
5882
self,
5983
recipe_id: str,
6084
app_info: AppInfo,
61-
api_key: str,
85+
api_key: Union[str, None],
6286
override: Union[InputOverrideConfig, None] = None,
6387
):
6488
super().__init__(recipe_id, app_info)
@@ -173,7 +197,7 @@ def get_all_cors_headers(self) -> List[str]:
173197

174198
@staticmethod
175199
def init(
176-
api_key: str,
200+
api_key: Union[str, None],
177201
override: Union[InputOverrideConfig, None] = None,
178202
):
179203
def func(app_info: AppInfo):
@@ -205,8 +229,7 @@ def reset():
205229
if ("SUPERTOKENS_ENV" not in environ) or (
206230
environ["SUPERTOKENS_ENV"] != "testing"
207231
):
208-
raise_general_exception(
209-
"calling testing function in non testing env")
232+
raise_general_exception("calling testing function in non testing env")
210233
DashboardRecipe.__instance = None
211234

212235
def return_api_id_if_can_handle_request(

supertokens_python/recipe/dashboard/utils.py

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,48 @@
1919
from supertokens_python.framework.request import BaseRequest
2020

2121
from supertokens_python.recipe.emailpassword import EmailPasswordRecipe
22-
from supertokens_python.recipe.emailpassword.asyncio import \
23-
get_user_by_id as ep_get_user_by_id
22+
from supertokens_python.recipe.emailpassword.asyncio import (
23+
get_user_by_id as ep_get_user_by_id,
24+
)
2425
from supertokens_python.recipe.passwordless import PasswordlessRecipe
25-
from supertokens_python.recipe.passwordless.asyncio import \
26-
get_user_by_id as pless_get_user_by_id
26+
from supertokens_python.recipe.passwordless.asyncio import (
27+
get_user_by_id as pless_get_user_by_id,
28+
)
2729
from supertokens_python.recipe.thirdparty import ThirdPartyRecipe
28-
from supertokens_python.recipe.thirdparty.asyncio import \
29-
get_user_by_id as tp_get_user_by_idx
30-
from supertokens_python.recipe.thirdpartyemailpassword import \
31-
ThirdPartyEmailPasswordRecipe
32-
from supertokens_python.recipe.thirdpartyemailpassword.asyncio import \
33-
get_user_by_id as tpep_get_user_by_id
34-
from supertokens_python.recipe.thirdpartypasswordless import \
35-
ThirdPartyPasswordlessRecipe
36-
from supertokens_python.recipe.thirdpartypasswordless.asyncio import \
37-
get_user_by_id as tppless_get_user_by_id
30+
from supertokens_python.recipe.thirdparty.asyncio import (
31+
get_user_by_id as tp_get_user_by_idx,
32+
)
33+
from supertokens_python.recipe.thirdpartyemailpassword import (
34+
ThirdPartyEmailPasswordRecipe,
35+
)
36+
from supertokens_python.recipe.thirdpartyemailpassword.asyncio import (
37+
get_user_by_id as tpep_get_user_by_id,
38+
)
39+
from supertokens_python.recipe.thirdpartypasswordless import (
40+
ThirdPartyPasswordlessRecipe,
41+
)
42+
from supertokens_python.recipe.thirdpartypasswordless.asyncio import (
43+
get_user_by_id as tppless_get_user_by_id,
44+
)
3845
from supertokens_python.types import User
3946
from supertokens_python.utils import Awaitable
4047

4148
from ...normalised_url_path import NormalisedURLPath
4249
from ...supertokens import AppInfo
43-
from .constants import (DASHBOARD_API, EMAIL_PASSSWORD_SIGNOUT,
44-
EMAIL_PASSWORD_SIGN_IN, USER_API,
45-
USER_EMAIL_VERIFY_API, USER_EMAIL_VERIFY_TOKEN_API,
46-
USER_METADATA_API, USER_PASSWORD_API, USER_SESSION_API,
47-
USERS_COUNT_API, USERS_LIST_GET_API, VALIDATE_KEY_API)
50+
from .constants import (
51+
DASHBOARD_API,
52+
EMAIL_PASSSWORD_SIGNOUT,
53+
EMAIL_PASSWORD_SIGN_IN,
54+
USER_API,
55+
USER_EMAIL_VERIFY_API,
56+
USER_EMAIL_VERIFY_TOKEN_API,
57+
USER_METADATA_API,
58+
USER_PASSWORD_API,
59+
USER_SESSION_API,
60+
USERS_COUNT_API,
61+
USERS_LIST_GET_API,
62+
VALIDATE_KEY_API,
63+
)
4864

4965
if TYPE_CHECKING:
5066
from .interfaces import APIInterface, RecipeInterface
@@ -132,8 +148,7 @@ def to_json(self) -> Dict[str, Any]:
132148
class InputOverrideConfig:
133149
def __init__(
134150
self,
135-
functions: Union[Callable[[RecipeInterface],
136-
RecipeInterface], None] = None,
151+
functions: Union[Callable[[RecipeInterface], RecipeInterface], None] = None,
137152
apis: Union[Callable[[APIInterface], APIInterface], None] = None,
138153
):
139154
self.functions = functions
@@ -143,8 +158,7 @@ def __init__(
143158
class OverrideConfig:
144159
def __init__(
145160
self,
146-
functions: Union[Callable[[RecipeInterface],
147-
RecipeInterface], None] = None,
161+
functions: Union[Callable[[RecipeInterface], RecipeInterface], None] = None,
148162
apis: Union[Callable[[APIInterface], APIInterface], None] = None,
149163
):
150164
self.functions = functions
@@ -153,10 +167,7 @@ def __init__(
153167

154168
class DashboardConfig:
155169
def __init__(
156-
self,
157-
api_key: str,
158-
override: OverrideConfig,
159-
auth_mode: str
170+
self, api_key: Union[str, None], override: OverrideConfig, auth_mode: str
160171
):
161172
self.api_key = api_key
162173
self.override = override
@@ -165,7 +176,7 @@ def __init__(
165176

166177
def validate_and_normalise_user_input(
167178
# app_info: AppInfo,
168-
api_key: str,
179+
api_key: Union[str, None],
169180
override: Optional[InputOverrideConfig] = None,
170181
) -> DashboardConfig:
171182

@@ -178,7 +189,7 @@ def validate_and_normalise_user_input(
178189
functions=override.functions,
179190
apis=override.apis,
180191
),
181-
"api-key" if api_key else "email-password"
192+
"api-key" if api_key else "email-password",
182193
)
183194

184195

@@ -190,8 +201,7 @@ def is_api_path(path: NormalisedURLPath, app_info: AppInfo) -> bool:
190201
if not path.startswith(dashboard_recipe_base_path):
191202
return False
192203

193-
path_without_dashboard_path = path.get_as_string_dangerous().split(DASHBOARD_API)[
194-
1]
204+
path_without_dashboard_path = path.get_as_string_dangerous().split(DASHBOARD_API)[1]
195205

196206
if len(path_without_dashboard_path) > 0 and path_without_dashboard_path[0] == "/":
197207
path_without_dashboard_path = path_without_dashboard_path[1:]
@@ -242,16 +252,15 @@ def __init__(self, user: UserWithMetadata, recipe: str):
242252

243253

244254
if TYPE_CHECKING:
245-
from supertokens_python.recipe.emailpassword.types import \
246-
User as EmailPasswordUser
247-
from supertokens_python.recipe.passwordless.types import \
248-
User as PasswordlessUser
249-
from supertokens_python.recipe.thirdparty.types import \
250-
User as ThirdPartyUser
251-
from supertokens_python.recipe.thirdpartyemailpassword.types import \
252-
User as ThirdPartyEmailPasswordUser
253-
from supertokens_python.recipe.thirdpartypasswordless.types import \
254-
User as ThirdPartyPasswordlessUser
255+
from supertokens_python.recipe.emailpassword.types import User as EmailPasswordUser
256+
from supertokens_python.recipe.passwordless.types import User as PasswordlessUser
257+
from supertokens_python.recipe.thirdparty.types import User as ThirdPartyUser
258+
from supertokens_python.recipe.thirdpartyemailpassword.types import (
259+
User as ThirdPartyEmailPasswordUser,
260+
)
261+
from supertokens_python.recipe.thirdpartypasswordless.types import (
262+
User as ThirdPartyPasswordlessUser,
263+
)
255264

256265
GetUserResult = Union[
257266
EmailPasswordUser,

0 commit comments

Comments
 (0)