Skip to content

Commit

Permalink
fixes more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Oct 2, 2024
1 parent 520a30b commit 8c6f331
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
36 changes: 21 additions & 15 deletions supertokens_python/recipe/thirdparty/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def to_json(self) -> Dict[str, Any]:
return {k: v for k, v in res.items() if v is not None}

@staticmethod
def from_json(json: Dict[str, Any]) -> UserFields:
def from_json(json: Optional[Dict[str, Any]]) -> Optional[UserFields]:
if json is None:
return None
return UserFields(
user_id=json.get("userId", None),
email=json.get("email", None),
Expand All @@ -170,12 +172,14 @@ def to_json(self) -> Dict[str, Any]:
return res

@staticmethod
def from_json(json: Dict[str, Any]) -> UserInfoMap:
def from_json(json: Optional[Dict[str, Any]]) -> Optional[UserInfoMap]:
if json is None:
return None
return UserInfoMap(
from_id_token_payload=UserFields.from_json(
json.get("fromIdTokenPayload", {})
json.get("fromIdTokenPayload", None)
),
from_user_info_api=UserFields.from_json(json.get("fromUserInfoAPI", {})),
from_user_info_api=UserFields.from_json(json.get("fromUserInfoAPI", None)),
)


Expand Down Expand Up @@ -394,22 +398,24 @@ def to_json(self) -> Dict[str, Any]:
def from_json(json: Dict[str, Any]) -> ProviderConfig:
return ProviderConfig(
third_party_id=json.get("thirdPartyId", ""),
name=json.get("name", ""),
name=json.get("name", None),
clients=[
ProviderClientConfig.from_json(c) for c in json.get("clients", [])
],
authorization_endpoint=json.get("authorizationEndpoint", ""),
authorization_endpoint=json.get("authorizationEndpoint", None),
authorization_endpoint_query_params=json.get(
"authorizationEndpointQueryParams", {}
"authorizationEndpointQueryParams", None
),
token_endpoint=json.get("tokenEndpoint", ""),
token_endpoint_body_params=json.get("tokenEndpointBodyParams", {}),
user_info_endpoint=json.get("userInfoEndpoint", ""),
user_info_endpoint_query_params=json.get("userInfoEndpointQueryParams", {}),
user_info_endpoint_headers=json.get("userInfoEndpointHeaders", {}),
jwks_uri=json.get("jwksURI", ""),
oidc_discovery_endpoint=json.get("oidcDiscoveryEndpoint", ""),
user_info_map=UserInfoMap.from_json(json.get("userInfoMap", {})),
token_endpoint=json.get("tokenEndpoint", None),
token_endpoint_body_params=json.get("tokenEndpointBodyParams", None),
user_info_endpoint=json.get("userInfoEndpoint", None),
user_info_endpoint_query_params=json.get(
"userInfoEndpointQueryParams", None
),
user_info_endpoint_headers=json.get("userInfoEndpointHeaders", None),
jwks_uri=json.get("jwksURI", None),
oidc_discovery_endpoint=json.get("oidcDiscoveryEndpoint", None),
user_info_map=UserInfoMap.from_json(json.get("userInfoMap", None)),
require_email=json.get("requireEmail", None),
validate_id_token_payload=None,
generate_fake_email=None,
Expand Down
8 changes: 4 additions & 4 deletions supertokens_python/recipe/thirdparty/providers/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,11 @@ async def get_user_info(


def NewProvider(
input: ProviderInput, # pylint: disable=redefined-builtin
input_: ProviderInput,
base_class: Callable[[ProviderConfig], Provider] = GenericProvider,
) -> Provider:
provider_instance = base_class(input.config)
if input.override is not None:
provider_instance = input.override(provider_instance)
provider_instance = base_class(input_.config)
if input_.override is not None:
provider_instance = input_.override(provider_instance)

return provider_instance
20 changes: 10 additions & 10 deletions tests/auth-react/flask-server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@
ClaimValidationError,
InvalidClaimsError,
)
from supertokens_python.recipe.thirdparty.provider import Provider, RedirectUriInfo
from supertokens_python.recipe.thirdparty.provider import (
Provider,
RedirectUriInfo,
)
from supertokens_python.recipe.emailpassword.interfaces import (
APIOptions as EPAPIOptions,
)
Expand Down Expand Up @@ -131,7 +134,10 @@
SessionClaimValidator,
SessionContainer,
)
from supertokens_python.recipe.thirdparty import ProviderConfig, ThirdPartyRecipe
from supertokens_python.recipe.thirdparty import (
ProviderConfig,
ThirdPartyRecipe,
)
from supertokens_python.recipe.thirdparty.interfaces import (
APIInterface as ThirdpartyAPIInterface,
ManuallyCreateOrUpdateUserOkResult,
Expand Down Expand Up @@ -1176,7 +1182,7 @@ def setup_tenant():
raise Exception("Should never come here")
tenant_id = body["tenantId"]
login_methods = body["loginMethods"]
core_config = body["coreConfig"]
core_config = "coreConfig" in body and body["coreConfig"] or {}

first_factors: List[str] = []
if login_methods.get("emailPassword", {}).get("enabled") == True:
Expand All @@ -1196,15 +1202,9 @@ def setup_tenant():

if login_methods.get("thirdParty", {}).get("providers") is not None:
for provider in login_methods["thirdParty"]["providers"]:
if (
len(provider) > 1
): # TODO: remove this once all tests pass, this is just for making sure we pass the right stuff into ProviderConfig
raise Exception("Pass more stuff into ProviderConfig:" + str(provider))
create_or_update_third_party_config(
tenant_id,
config=ProviderConfig(
third_party_id=provider["id"],
),
config=ProviderConfig.from_json(provider),
)

return jsonify({"status": "OK", "createdNew": core_resp.created_new})
Expand Down

0 comments on commit 8c6f331

Please sign in to comment.