Skip to content

Commit 0ee1a53

Browse files
committed
refactor: Improve interface and variables
1 parent 2cd6cb5 commit 0ee1a53

File tree

7 files changed

+31
-26
lines changed

7 files changed

+31
-26
lines changed

supertokens_python/framework/django/django_request.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def __init__(self, request: HttpRequest):
2929
super().__init__()
3030
self.request = request
3131

32+
def get_original_url(self) -> str:
33+
return self.request.get_raw_uri()
34+
3235
def get_query_param(
3336
self, key: str, default: Union[str, None] = None
3437
) -> Union[str, None]:

supertokens_python/framework/fastapi/fastapi_request.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def __init__(self, request: Request):
2828
super().__init__()
2929
self.request = request
3030

31+
def get_original_url(self) -> str:
32+
return self.request.url.components.geturl()
33+
3134
def get_query_param(
3235
self, key: str, default: Union[str, None] = None
3336
) -> Union[str, None]:

supertokens_python/framework/flask/flask_request.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def __init__(self, req: Request):
2727
super().__init__()
2828
self.request = req
2929

30+
def get_original_url(self) -> str:
31+
return self.request.url
32+
3033
def get_query_param(self, key: str, default: Union[str, None] = None):
3134
return self.request.args.get(key, default)
3235

supertokens_python/recipe/dashboard/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
USER_SESSION_API = "/api/user/sessions"
99
USER_PASSWORD_API = "/api/user/password"
1010
USER_EMAIL_VERIFY_TOKEN_API = "/api/user/email/verify/token"
11-
EMAIL_PASSWORD_SIGN_IN = "/api/signin"
12-
EMAIL_PASSSWORD_SIGNOUT = "/api/signout"
11+
SIGN_IN_API = "/api/signin"
12+
SIGN_OUT_API = "/api/signout"
1313
SEARCH_TAGS_API = "/api/search/tags"
1414
DASHBOARD_ANALYTICS_API = "/api/analytics"
1515
TENANTS_LIST_API = "/api/tenants/list"

supertokens_python/recipe/dashboard/recipe.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from __future__ import annotations
1515

1616
from os import environ
17-
from typing import TYPE_CHECKING, Awaitable, Callable, List, Optional, Union, Dict, Any
17+
from typing import TYPE_CHECKING, Awaitable, Callable, List, Optional, Dict, Any
1818

1919
from supertokens_python.normalised_url_path import NormalisedURLPath
2020
from supertokens_python.recipe_module import APIHandled, RecipeModule
@@ -59,8 +59,8 @@
5959
from .constants import (
6060
DASHBOARD_ANALYTICS_API,
6161
DASHBOARD_API,
62-
EMAIL_PASSSWORD_SIGNOUT,
63-
EMAIL_PASSWORD_SIGN_IN,
62+
SIGN_OUT_API,
63+
SIGN_IN_API,
6464
SEARCH_TAGS_API,
6565
USER_API,
6666
USER_EMAIL_VERIFY_API,
@@ -125,11 +125,9 @@ def get_apis_handled(self) -> List[APIHandled]:
125125
False,
126126
),
127127
APIHandled(
128-
NormalisedURLPath(
129-
get_api_path_with_dashboard_base(EMAIL_PASSWORD_SIGN_IN)
130-
),
128+
NormalisedURLPath(get_api_path_with_dashboard_base(SIGN_IN_API)),
131129
"post",
132-
EMAIL_PASSWORD_SIGN_IN,
130+
SIGN_IN_API,
133131
False,
134132
),
135133
APIHandled(
@@ -139,11 +137,9 @@ def get_apis_handled(self) -> List[APIHandled]:
139137
False,
140138
),
141139
APIHandled(
142-
NormalisedURLPath(
143-
get_api_path_with_dashboard_base(EMAIL_PASSSWORD_SIGNOUT)
144-
),
140+
NormalisedURLPath(get_api_path_with_dashboard_base(SIGN_OUT_API)),
145141
"post",
146-
EMAIL_PASSSWORD_SIGNOUT,
142+
SIGN_OUT_API,
147143
False,
148144
),
149145
APIHandled(
@@ -279,7 +275,7 @@ async def handle_api_request(
279275
return await handle_validate_key_api(
280276
self.api_implementation, api_options, user_context
281277
)
282-
if request_id == EMAIL_PASSWORD_SIGN_IN:
278+
if request_id == SIGN_IN_API:
283279
return await handle_emailpassword_signin_api(
284280
self.api_implementation, api_options, user_context
285281
)
@@ -320,7 +316,7 @@ async def handle_api_request(
320316
api_function = handle_user_password_put
321317
elif request_id == USER_EMAIL_VERIFY_TOKEN_API:
322318
api_function = handle_email_verify_token_post
323-
elif request_id == EMAIL_PASSSWORD_SIGNOUT:
319+
elif request_id == SIGN_OUT_API:
324320
api_function = handle_emailpassword_signout_api
325321
elif request_id == SEARCH_TAGS_API:
326322
api_function = handle_get_tags
@@ -352,7 +348,7 @@ def get_all_cors_headers(self) -> List[str]:
352348
@staticmethod
353349
def init(
354350
api_key: Optional[str],
355-
admins: Optional[List[str]],
351+
admins: Optional[List[str]] = None,
356352
override: Optional[InputOverrideConfig] = None,
357353
):
358354
def func(app_info: AppInfo):

supertokens_python/recipe/dashboard/recipe_implementation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
from supertokens_python.constants import DASHBOARD_VERSION
1919
from supertokens_python.framework import BaseRequest
2020
from supertokens_python.normalised_url_path import NormalisedURLPath
21-
from supertokens_python.utils import log_debug_message
21+
from supertokens_python.utils import log_debug_message, normalise_http_method
2222
from supertokens_python.querier import Querier
2323
from supertokens_python.recipe.dashboard.constants import (
2424
DASHBOARD_ANALYTICS_API,
25-
EMAIL_PASSSWORD_SIGNOUT,
25+
SIGN_OUT_API,
2626
)
2727

2828
from .interfaces import RecipeInterface
@@ -58,13 +58,13 @@ async def should_allow_access(
5858

5959
# For all non GET requests we also want to check if the
6060
# user is allowed to perform this operation
61-
if request.method() != "GET": # TODO: Use normalize http method?
61+
if normalise_http_method(request.method()) != "get":
6262
# We dont want to block the analytics API
6363
if request.get_original_url().startswith(DASHBOARD_ANALYTICS_API):
6464
return True
6565

6666
# We do not want to block the sign out request
67-
if request.get_original_url().endswith(EMAIL_PASSSWORD_SIGNOUT):
67+
if request.get_original_url().endswith(SIGN_OUT_API):
6868
return True
6969

7070
admins = config.admins

supertokens_python/recipe/dashboard/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
from .constants import (
5050
DASHBOARD_ANALYTICS_API,
5151
DASHBOARD_API,
52-
EMAIL_PASSSWORD_SIGNOUT,
53-
EMAIL_PASSWORD_SIGN_IN,
52+
SIGN_OUT_API,
53+
SIGN_IN_API,
5454
SEARCH_TAGS_API,
5555
USER_API,
5656
USER_EMAIL_VERIFY_API,
@@ -259,10 +259,10 @@ def get_api_if_matched(path: NormalisedURLPath, method: str) -> Optional[str]:
259259
return USER_PASSWORD_API
260260
if path_str.endswith(USER_EMAIL_VERIFY_TOKEN_API) and method == "post":
261261
return USER_EMAIL_VERIFY_TOKEN_API
262-
if path_str.endswith(EMAIL_PASSWORD_SIGN_IN) and method == "post":
263-
return EMAIL_PASSWORD_SIGN_IN
264-
if path_str.endswith(EMAIL_PASSSWORD_SIGNOUT) and method == "post":
265-
return EMAIL_PASSSWORD_SIGNOUT
262+
if path_str.endswith(SIGN_IN_API) and method == "post":
263+
return SIGN_IN_API
264+
if path_str.endswith(SIGN_OUT_API) and method == "post":
265+
return SIGN_OUT_API
266266
if path_str.endswith(SEARCH_TAGS_API) and method == "get":
267267
return SEARCH_TAGS_API
268268
if path_str.endswith(DASHBOARD_ANALYTICS_API) and method == "post":

0 commit comments

Comments
 (0)