15
15
16
16
from typing import TYPE_CHECKING , Any , Callable , Dict , Optional , Union
17
17
18
+ if TYPE_CHECKING :
19
+ from supertokens_python .framework .request import BaseRequest
20
+
18
21
from supertokens_python .recipe .emailpassword import EmailPasswordRecipe
19
- from supertokens_python .recipe .emailpassword .asyncio import (
20
- get_user_by_id as ep_get_user_by_id ,
21
- )
22
+ from supertokens_python .recipe .emailpassword .asyncio import \
23
+ get_user_by_id as ep_get_user_by_id
22
24
from supertokens_python .recipe .passwordless import PasswordlessRecipe
23
- from supertokens_python .recipe .passwordless .asyncio import (
24
- get_user_by_id as pless_get_user_by_id ,
25
- )
25
+ from supertokens_python .recipe .passwordless .asyncio import \
26
+ get_user_by_id as pless_get_user_by_id
26
27
from supertokens_python .recipe .thirdparty import ThirdPartyRecipe
27
- from supertokens_python .recipe .thirdparty .asyncio import (
28
- get_user_by_id as tp_get_user_by_idx ,
29
- )
30
- from supertokens_python .recipe .thirdpartyemailpassword import (
31
- ThirdPartyEmailPasswordRecipe ,
32
- )
33
- from supertokens_python .recipe .thirdpartyemailpassword .asyncio import (
34
- get_user_by_id as tpep_get_user_by_id ,
35
- )
36
- from supertokens_python .recipe .thirdpartypasswordless import (
37
- ThirdPartyPasswordlessRecipe ,
38
- )
39
- from supertokens_python .recipe .thirdpartypasswordless .asyncio import (
40
- get_user_by_id as tppless_get_user_by_id ,
41
- )
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
42
38
from supertokens_python .types import User
43
39
from supertokens_python .utils import Awaitable
44
40
45
41
from ...normalised_url_path import NormalisedURLPath
46
42
from ...supertokens import AppInfo
47
- from .constants import (
48
- DASHBOARD_API ,
49
- USER_API ,
50
- USER_EMAIL_VERIFY_API ,
51
- USER_EMAIL_VERIFY_TOKEN_API ,
52
- USER_METADATA_API ,
53
- USER_PASSWORD_API ,
54
- USER_SESSION_API ,
55
- USERS_COUNT_API ,
56
- USERS_LIST_GET_API ,
57
- VALIDATE_KEY_API ,
58
- )
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 )
59
48
60
49
if TYPE_CHECKING :
61
50
from .interfaces import APIInterface , RecipeInterface
@@ -143,7 +132,8 @@ def to_json(self) -> Dict[str, Any]:
143
132
class InputOverrideConfig :
144
133
def __init__ (
145
134
self ,
146
- functions : Union [Callable [[RecipeInterface ], RecipeInterface ], None ] = None ,
135
+ functions : Union [Callable [[RecipeInterface ],
136
+ RecipeInterface ], None ] = None ,
147
137
apis : Union [Callable [[APIInterface ], APIInterface ], None ] = None ,
148
138
):
149
139
self .functions = functions
@@ -153,7 +143,8 @@ def __init__(
153
143
class OverrideConfig :
154
144
def __init__ (
155
145
self ,
156
- functions : Union [Callable [[RecipeInterface ], RecipeInterface ], None ] = None ,
146
+ functions : Union [Callable [[RecipeInterface ],
147
+ RecipeInterface ], None ] = None ,
157
148
apis : Union [Callable [[APIInterface ], APIInterface ], None ] = None ,
158
149
):
159
150
self .functions = functions
@@ -165,18 +156,18 @@ def __init__(
165
156
self ,
166
157
api_key : str ,
167
158
override : OverrideConfig ,
159
+ auth_mode : str
168
160
):
169
161
self .api_key = api_key
170
162
self .override = override
163
+ self .auth_mode = auth_mode
171
164
172
165
173
166
def validate_and_normalise_user_input (
174
167
# app_info: AppInfo,
175
168
api_key : str ,
176
169
override : Optional [InputOverrideConfig ] = None ,
177
170
) -> DashboardConfig :
178
- if api_key .strip () == "" :
179
- raise Exception ("apiKey provided to Dashboard recipe cannot be empty" )
180
171
181
172
if override is None :
182
173
override = InputOverrideConfig ()
@@ -187,6 +178,7 @@ def validate_and_normalise_user_input(
187
178
functions = override .functions ,
188
179
apis = override .apis ,
189
180
),
181
+ "api-key" if api_key else "email-password"
190
182
)
191
183
192
184
@@ -198,7 +190,8 @@ def is_api_path(path: NormalisedURLPath, app_info: AppInfo) -> bool:
198
190
if not path .startswith (dashboard_recipe_base_path ):
199
191
return False
200
192
201
- path_without_dashboard_path = path .get_as_string_dangerous ().split (DASHBOARD_API )[1 ]
193
+ path_without_dashboard_path = path .get_as_string_dangerous ().split (DASHBOARD_API )[
194
+ 1 ]
202
195
203
196
if len (path_without_dashboard_path ) > 0 and path_without_dashboard_path [0 ] == "/" :
204
197
path_without_dashboard_path = path_without_dashboard_path [1 :]
@@ -230,6 +223,10 @@ def get_api_if_matched(path: NormalisedURLPath, method: str) -> Optional[str]:
230
223
return USER_PASSWORD_API
231
224
if path_str .endswith (USER_EMAIL_VERIFY_TOKEN_API ) and method == "post" :
232
225
return USER_EMAIL_VERIFY_TOKEN_API
226
+ if path_str .endswith (EMAIL_PASSWORD_SIGN_IN ) and method == "post" :
227
+ return EMAIL_PASSWORD_SIGN_IN
228
+ if path_str .endswith (EMAIL_PASSSWORD_SIGNOUT ) and method == "post" :
229
+ return EMAIL_PASSSWORD_SIGNOUT
233
230
234
231
return None
235
232
@@ -245,15 +242,16 @@ def __init__(self, user: UserWithMetadata, recipe: str):
245
242
246
243
247
244
if TYPE_CHECKING :
248
- from supertokens_python .recipe .emailpassword .types import User as EmailPasswordUser
249
- from supertokens_python .recipe .passwordless .types import User as PasswordlessUser
250
- from supertokens_python .recipe .thirdparty .types import User as ThirdPartyUser
251
- from supertokens_python .recipe .thirdpartyemailpassword .types import (
252
- User as ThirdPartyEmailPasswordUser ,
253
- )
254
- from supertokens_python .recipe .thirdpartypasswordless .types import (
255
- User as ThirdPartyPasswordlessUser ,
256
- )
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
257
255
258
256
GetUserResult = Union [
259
257
EmailPasswordUser ,
@@ -385,3 +383,10 @@ def is_recipe_initialised(recipeId: str) -> bool:
385
383
pass
386
384
387
385
return isRecipeInitialised
386
+
387
+
388
+ def validate_APIKey (req : BaseRequest , config : DashboardConfig ) -> bool :
389
+ apiKeyHeaderValue = req .get_header ("authorization" )
390
+ if not apiKeyHeaderValue :
391
+ return False
392
+ return apiKeyHeaderValue == config .api_key
0 commit comments