diff --git a/supertokens_python/recipe/thirdparty/providers/active_directory.py b/supertokens_python/recipe/thirdparty/providers/active_directory.py index f3930f376..09839ef74 100644 --- a/supertokens_python/recipe/thirdparty/providers/active_directory.py +++ b/supertokens_python/recipe/thirdparty/providers/active_directory.py @@ -54,13 +54,4 @@ def ActiveDirectory( if input.config.name is None: input.config.name = "Active Directory" - if input.config.user_info_map is None: - input.config.user_info_map = UserInfoMap(UserFields(), UserFields()) - - if input.config.user_info_map.from_id_token_payload.user_id is None: - input.config.user_info_map.from_id_token_payload.user_id = "sub" - - if input.config.user_info_map.from_id_token_payload.email is None: - input.config.user_info_map.from_id_token_payload.email = "email" - return NewProvider(input, ActiveDirectoryImpl) diff --git a/supertokens_python/recipe/thirdparty/providers/custom.py b/supertokens_python/recipe/thirdparty/providers/custom.py index 3d736346b..a84ffa107 100644 --- a/supertokens_python/recipe/thirdparty/providers/custom.py +++ b/supertokens_python/recipe/thirdparty/providers/custom.py @@ -215,6 +215,8 @@ def _normalize_input( # pylint: disable=no-self-use from_user_info_api=UserFields(), ) + # These are safe defaults common to most providers. Each provider + # implementations override these as necessary if input_config.user_info_map.from_id_token_payload.user_id is None: input_config.user_info_map.from_id_token_payload.user_id = "sub" @@ -226,6 +228,17 @@ def _normalize_input( # pylint: disable=no-self-use "email_verified" ) + if input_config.user_info_map.from_user_info_api.user_id is None: + input_config.user_info_map.from_user_info_api.user_id = "sub" + + if input_config.user_info_map.from_user_info_api.email is None: + input_config.user_info_map.from_user_info_api.email = "email" + + if input_config.user_info_map.from_user_info_api.email_verified is None: + input_config.user_info_map.from_user_info_api.email_verified = ( + "email_verified" + ) + if input_config.generate_fake_email is None: async def default_generate_fake_email( diff --git a/supertokens_python/recipe/thirdparty/providers/facebook.py b/supertokens_python/recipe/thirdparty/providers/facebook.py index 6cce0e16a..11427e15a 100644 --- a/supertokens_python/recipe/thirdparty/providers/facebook.py +++ b/supertokens_python/recipe/thirdparty/providers/facebook.py @@ -76,10 +76,4 @@ def Facebook(input: ProviderInput) -> Provider: # pylint: disable=redefined-bui if input.config.user_info_map.from_user_info_api.user_id is None: input.config.user_info_map.from_user_info_api.user_id = "id" - if input.config.user_info_map.from_user_info_api.email is None: - input.config.user_info_map.from_user_info_api.email = "email" - - if input.config.user_info_map.from_user_info_api.email_verified is None: - input.config.user_info_map.from_user_info_api.email = "verified" - return NewProvider(input, FacebookImpl) diff --git a/supertokens_python/recipe/thirdparty/providers/google.py b/supertokens_python/recipe/thirdparty/providers/google.py index 86f9f6b89..b6d0b5ce6 100644 --- a/supertokens_python/recipe/thirdparty/providers/google.py +++ b/supertokens_python/recipe/thirdparty/providers/google.py @@ -54,15 +54,6 @@ def Google( if input.config.user_info_map is None: input.config.user_info_map = UserInfoMap(UserFields(), UserFields()) - if input.config.user_info_map.from_user_info_api.user_id is None: - input.config.user_info_map.from_user_info_api.user_id = "id" - - if input.config.user_info_map.from_user_info_api.email is None: - input.config.user_info_map.from_user_info_api.email = "email" - - if input.config.user_info_map.from_user_info_api.email_verified is None: - input.config.user_info_map.from_user_info_api.email = "email_verified" - if input.config.authorization_endpoint_query_params is None: input.config.authorization_endpoint_query_params = {} diff --git a/supertokens_python/recipe/thirdparty/providers/okta.py b/supertokens_python/recipe/thirdparty/providers/okta.py index 61fb88845..8f98c397c 100644 --- a/supertokens_python/recipe/thirdparty/providers/okta.py +++ b/supertokens_python/recipe/thirdparty/providers/okta.py @@ -39,7 +39,7 @@ async def get_config_for_client_type( ) config.oidc_discovery_endpoint = ( - f"{config.additional_config.get('oktaDomain')}.okta.com" + f"{config.additional_config.get('oktaDomain')}" ) if config.scope is None: @@ -54,13 +54,4 @@ def Okta(input: ProviderInput) -> Provider: # pylint: disable=redefined-builtin if input.config.name is None: input.config.name = "Okta" - if input.config.user_info_map is None: - input.config.user_info_map = UserInfoMap(UserFields(), UserFields()) - - if input.config.user_info_map.from_id_token_payload.user_id is None: - input.config.user_info_map.from_id_token_payload.user_id = "sub" - - if input.config.user_info_map.from_id_token_payload.email is None: - input.config.user_info_map.from_id_token_payload.email = "email" - return NewProvider(input, OktaImpl) diff --git a/tests/thirdparty/test_multitenancy.py b/tests/thirdparty/test_multitenancy.py index 11c5919b0..4c3a5a58c 100644 --- a/tests/thirdparty/test_multitenancy.py +++ b/tests/thirdparty/test_multitenancy.py @@ -223,3 +223,41 @@ async def test_get_provider(): provider6 = await get_provider("t3", "linkedin", None) assert provider6 is not None assert provider6.config.third_party_id == "linkedin" + + +async def test_get_provider_returns_correct_config_from_core(): + args = get_st_init_args([thirdparty.init()]) + init(**args) # type: ignore + start_st() + setup_multitenancy_feature() + + await create_or_update_third_party_config( + "public", + thirdparty.ProviderConfig( + "google", + clients=[ + thirdparty.ProviderClientConfig( + client_id="core-client-id", + client_secret="core-secret", + ) + ], + ), + ) + + thirdparty_info = await get_provider("public", "google") + assert thirdparty_info is not None + assert thirdparty_info.config.third_party_id == "google" + + client = thirdparty_info.config.clients[0] + assert client.client_id == "core-client-id" + assert client.client_secret == "core-secret" + assert thirdparty_info.config.user_info_map.from_id_token_payload == { + "userId": "sub", + "email": "email", + "emailVerified": "email_verified", + } + assert thirdparty_info.config.user_info_map.from_user_info_api == { + "userId": "sub", + "email": "email", + "emailVerified": "email_verified", + }