1+ # Copyright (c) 2023, VRAI Labs and/or its affiliates. All rights reserved.
2+ #
3+ # This software is licensed under the Apache License, Version 2.0 (the
4+ # "License") as published by the Apache Software Foundation.
5+ #
6+ # You may not use this file except in compliance with the License. You may
7+ # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+ # License for the specific language governing permissions and limitations
13+ # under the License.
14+
115from __future__ import annotations
16+ import importlib
217
318from typing import Any , Dict , Optional , Set
419
1530 MFAClaimValue ,
1631 MFARequirementList ,
1732)
18- from .utils import update_and_get_mfa_related_info_in_session
1933
2034
2135class HasCompletedRequirementListSCV (SessionClaimValidator ):
@@ -29,14 +43,10 @@ def __init__(
2943 self .claim : MultiFactorAuthClaimClass = claim
3044 self .requirement_list = requirement_list
3145
32- async def should_refetch (
46+ def should_refetch (
3347 self , payload : Dict [str , Any ], user_context : Dict [str , Any ]
3448 ) -> bool :
35- return (
36- True
37- if self .claim .key not in payload or not payload [self .claim .key ]
38- else False
39- )
49+ return bool (self .claim .key not in payload or not payload [self .claim .key ])
4050
4151 async def validate (
4252 self , payload : JSONObject , user_context : Dict [str , Any ]
@@ -65,7 +75,7 @@ async def validate(
6575
6676 factor_ids = next_set_of_unsatisfied_factors .factor_ids
6777
68- if next_set_of_unsatisfied_factors .type == "string" :
78+ if next_set_of_unsatisfied_factors .type_ == "string" :
6979 return ClaimValidationResult (
7080 is_valid = False ,
7181 reason = {
@@ -74,7 +84,7 @@ async def validate(
7484 },
7585 )
7686
77- elif next_set_of_unsatisfied_factors .type == "oneOf" :
87+ elif next_set_of_unsatisfied_factors .type_ == "oneOf" :
7888 return ClaimValidationResult (
7989 is_valid = False ,
8090 reason = {
@@ -101,15 +111,11 @@ def __init__(
101111 super ().__init__ (id_ )
102112 self .claim = claim
103113
104- async def should_refetch (
114+ def should_refetch (
105115 self , payload : Dict [str , Any ], user_context : Dict [str , Any ]
106116 ) -> bool :
107117 assert self .claim is not None
108- return (
109- True
110- if self .claim .key not in payload or not payload [self .claim .key ]
111- else False
112- )
118+ return bool (self .claim .key not in payload or not payload [self .claim .key ])
113119
114120 async def validate (
115121 self , payload : JSONObject , user_context : Dict [str , Any ]
@@ -161,13 +167,17 @@ def __init__(self, key: Optional[str] = None):
161167 key = key or "st-mfa"
162168
163169 async def fetch_value (
164- user_id : str ,
170+ _user_id : str ,
165171 recipe_user_id : RecipeUserId ,
166172 tenant_id : str ,
167173 current_payload : Dict [str , Any ],
168174 user_context : Dict [str , Any ],
169175 ) -> MFAClaimValue :
170- mfa_info = await update_and_get_mfa_related_info_in_session (
176+ module = importlib .import_module (
177+ "supertokens_python.recipe.multifactorauth.utils"
178+ )
179+
180+ mfa_info = await module .update_and_get_mfa_related_info_in_session (
171181 input_session_recipe_user_id = recipe_user_id ,
172182 input_tenant_id = tenant_id ,
173183 input_access_token_payload = current_payload ,
@@ -209,9 +219,11 @@ def get_next_set_of_unsatisfied_factors(
209219 )
210220
211221 if len (next_factors ) > 0 :
212- return FactorIdsAndType (factor_ids = list (next_factors ), type = factor_type )
222+ return FactorIdsAndType (
223+ factor_ids = list (next_factors ), type_ = factor_type
224+ )
213225
214- return FactorIdsAndType (factor_ids = [], type = "string" )
226+ return FactorIdsAndType (factor_ids = [], type_ = "string" )
215227
216228 def add_to_payload_ (
217229 self ,
0 commit comments