From fa03181d5cce581e9d17e6aed2e026ca107dfb1f Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Mon, 30 Sep 2024 19:52:48 +0530 Subject: [PATCH] fixes a few bugs --- .../recipe/accountlinking/utils.py | 2 +- .../multi_factor_auth_claim.py | 8 +++- tests/auth-react/flask-server/app.py | 40 +++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/supertokens_python/recipe/accountlinking/utils.py b/supertokens_python/recipe/accountlinking/utils.py index 5f0209fd..6aa12765 100644 --- a/supertokens_python/recipe/accountlinking/utils.py +++ b/supertokens_python/recipe/accountlinking/utils.py @@ -52,7 +52,7 @@ async def default_should_do_automatic_account_linking( def recipe_init_defined_should_do_automatic_account_linking() -> bool: - return _did_use_default_should_do_automatic_account_linking + return not _did_use_default_should_do_automatic_account_linking def validate_and_normalise_user_input( diff --git a/supertokens_python/recipe/multifactorauth/multi_factor_auth_claim.py b/supertokens_python/recipe/multifactorauth/multi_factor_auth_claim.py index 4193697a..3c4bd655 100644 --- a/supertokens_python/recipe/multifactorauth/multi_factor_auth_claim.py +++ b/supertokens_python/recipe/multifactorauth/multi_factor_auth_claim.py @@ -59,7 +59,9 @@ async def validate( "This should never happen, claim value not present in payload" ) - claim_val: MFAClaimValue = payload[self.claim.key] + claim_val: MFAClaimValue = MFAClaimValue( + c=payload[self.claim.key]["c"], v=payload[self.claim.key]["v"] + ) completed_factors = claim_val.c next_set_of_unsatisfied_factors = ( @@ -125,7 +127,9 @@ async def validate( raise Exception( "This should never happen, claim value not present in payload" ) - claim_val: MFAClaimValue = payload[self.claim.key] + claim_val: MFAClaimValue = MFAClaimValue( + c=payload[self.claim.key]["c"], v=payload[self.claim.key]["v"] + ) return ClaimValidationResult( is_valid=claim_val.v, diff --git a/tests/auth-react/flask-server/app.py b/tests/auth-react/flask-server/app.py index 55ed847c..fabef9b3 100644 --- a/tests/auth-react/flask-server/app.py +++ b/tests/auth-react/flask-server/app.py @@ -321,6 +321,30 @@ async def get_user_info( # pylint: disable=no-self-use return oi +def mock_provider_override(oi: Provider) -> Provider: + async def get_user_info( + oauth_tokens: Dict[str, Any], + user_context: Dict[str, Any], + ) -> UserInfo: + user_id = oauth_tokens.get("userId", "user") + email = oauth_tokens.get("email", "email@test.com") + is_verified = oauth_tokens.get("isVerified", "true").lower() != "false" + + return UserInfo( + user_id, UserInfoEmail(email, is_verified), raw_user_info_from_provider=None + ) + + async def exchange_auth_code_for_oauth_tokens( + redirect_uri_info: RedirectUriInfo, + user_context: Dict[str, Any], + ) -> Dict[str, Any]: + return redirect_uri_info.redirect_uri_query_params + + oi.exchange_auth_code_for_oauth_tokens = exchange_auth_code_for_oauth_tokens + oi.get_user_info = get_user_info + return oi + + def custom_init(): global contact_method global flow_type @@ -713,6 +737,21 @@ async def resend_code_post( ), override=auth0_provider_override, ), + thirdparty.ProviderInput( + config=thirdparty.ProviderConfig( + third_party_id="mock-provider", + name="Mock Provider", + authorization_endpoint=get_website_domain() + "/mockProvider/auth", + token_endpoint=get_website_domain() + "/mockProvider/token", + clients=[ + thirdparty.ProviderClientConfig( + client_id="supertokens", + client_secret="", + ) + ], + ), + override=mock_provider_override, + ), ] global enabled_providers @@ -1386,6 +1425,7 @@ def index(_: str): @app.errorhandler(Exception) # type: ignore def all_exception_handler(e: Exception): + print(e) return "Error", 500