|
12 | 12 | # License for the specific language governing permissions and limitations |
13 | 13 | # under the License. |
14 | 14 |
|
15 | | -from typing import Optional, Union, cast |
| 15 | +from typing import List, Optional, Union, cast |
16 | 16 |
|
17 | 17 | from typing_extensions import Unpack |
18 | 18 |
|
|
23 | 23 | post_auth_checks, |
24 | 24 | pre_auth_checks, |
25 | 25 | ) |
| 26 | +from supertokens_python.exceptions import raise_general_exception |
26 | 27 | from supertokens_python.recipe.accountlinking.recipe import AccountLinkingRecipe |
27 | 28 | from supertokens_python.recipe.accountlinking.types import ( |
28 | 29 | AccountInfoWithRecipeId, |
@@ -1084,14 +1085,34 @@ async def list_credentials_get( |
1084 | 1085 | user_context: UserContext, |
1085 | 1086 | session: SessionContainer, |
1086 | 1087 | ) -> ListCredentialsGETResponse: |
1087 | | - list_credentials_response = ( |
1088 | | - await options.recipe_implementation.list_credentials( |
1089 | | - recipe_user_id=session.get_recipe_user_id().get_as_string(), |
1090 | | - user_context=user_context, |
1091 | | - ) |
| 1088 | + existing_user = await get_user( |
| 1089 | + user_id=session.get_user_id(), |
| 1090 | + user_context=user_context, |
1092 | 1091 | ) |
| 1092 | + if existing_user is None: |
| 1093 | + raise_general_exception("User not found") |
| 1094 | + |
| 1095 | + recipe_user_ids = [ |
| 1096 | + lm.recipe_user_id |
| 1097 | + for lm in existing_user.login_methods |
| 1098 | + if lm.recipe_id == "webauthn" |
| 1099 | + ] |
1093 | 1100 |
|
1094 | | - return list_credentials_response |
| 1101 | + credentials: List[ListCredentialsGETResponse.Credential] = [] |
| 1102 | + |
| 1103 | + for recipe_user_id in recipe_user_ids: |
| 1104 | + list_credentials_response = ( |
| 1105 | + await options.recipe_implementation.list_credentials( |
| 1106 | + recipe_user_id=recipe_user_id.get_as_string(), |
| 1107 | + user_context=user_context, |
| 1108 | + ) |
| 1109 | + ) |
| 1110 | + |
| 1111 | + credentials.extend(list_credentials_response.credentials) |
| 1112 | + |
| 1113 | + return ListCredentialsGETResponse( |
| 1114 | + credentials=credentials, |
| 1115 | + ) |
1095 | 1116 |
|
1096 | 1117 | async def register_credential_post( |
1097 | 1118 | self, |
@@ -1176,10 +1197,26 @@ async def remove_credential_post( |
1176 | 1197 | ] |
1177 | 1198 | ) |
1178 | 1199 |
|
| 1200 | + user = await get_user(session.get_user_id(), user_context=user_context) |
| 1201 | + if user is None: |
| 1202 | + raise_general_exception("User not found") |
| 1203 | + |
| 1204 | + required_login_methods = [ |
| 1205 | + lm |
| 1206 | + for lm in user.login_methods |
| 1207 | + if lm.recipe_id == "webauthn" |
| 1208 | + and lm.webauthn is not None |
| 1209 | + and webauthn_credential_id in lm.webauthn.credential_ids |
| 1210 | + ] |
| 1211 | + if len(required_login_methods) == 0: |
| 1212 | + raise_general_exception("User not found") |
| 1213 | + |
| 1214 | + recipe_user_id = required_login_methods[0].recipe_user_id |
| 1215 | + |
1179 | 1216 | remove_credential_response = ( |
1180 | 1217 | await options.recipe_implementation.remove_credential( |
1181 | 1218 | webauthn_credential_id=webauthn_credential_id, |
1182 | | - recipe_user_id=session.get_recipe_user_id().get_as_string(), |
| 1219 | + recipe_user_id=recipe_user_id.get_as_string(), |
1183 | 1220 | user_context=user_context, |
1184 | 1221 | ) |
1185 | 1222 | ) |
|
0 commit comments