Skip to content

Commit

Permalink
fixes a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Sep 30, 2024
1 parent cfe84f5 commit fa03181
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion supertokens_python/recipe/accountlinking/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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,
Expand Down
40 changes: 40 additions & 0 deletions tests/auth-react/flask-server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 protected]")
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1386,6 +1425,7 @@ def index(_: str):

@app.errorhandler(Exception) # type: ignore
def all_exception_handler(e: Exception):
print(e)
return "Error", 500


Expand Down

0 comments on commit fa03181

Please sign in to comment.