Skip to content

Commit

Permalink
Merge pull request #796 from supertokens/python-tp-override
Browse files Browse the repository at this point in the history
fix: python custom provider override snippet
  • Loading branch information
rishabhpoddar authored May 28, 2024
2 parents e72aca8 + 498f2e1 commit 4f59db3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,13 +612,9 @@ from supertokens_python.recipe.thirdparty.provider import ProviderClientConfig,
from supertokens_python.recipe.thirdparty.types import UserInfo, UserInfoEmail, RawUserInfoFromProvider
from typing import Dict, Any

class CustomProvider(Provider):
def __init__(self):
super().__init__('<PROVIDER_ID>', ProviderConfigForClient(
client_id='<CLIENT_ID>',
))

async def get_user_info(self, oauth_tokens: Dict[str, Any], user_context: Dict[str, Any]) -> UserInfo:
def override_custom_provider(provider: Provider) -> Provider:
async def get_user_info(oauth_tokens: Dict[str, Any], user_context: Dict[str, Any]) -> UserInfo:
return UserInfo(
third_party_user_id="...",
email=UserInfoEmail(
Expand All @@ -633,9 +629,9 @@ class CustomProvider(Provider):
},
),
)
provider.get_user_info = get_user_info
return provider

def get_custom_provider(provider: Provider) -> Provider:
return CustomProvider()

init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
Expand Down Expand Up @@ -665,7 +661,7 @@ init(
},
token_endpoint="https://example.com/oauth/token",
),
override=get_custom_provider
override=override_custom_provider
),
]
^{pythonSignInUpFeatureEnd}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,13 +612,9 @@ from supertokens_python.recipe.thirdparty.provider import ProviderClientConfig,
from supertokens_python.recipe.thirdparty.types import UserInfo, UserInfoEmail, RawUserInfoFromProvider
from typing import Dict, Any

class CustomProvider(Provider):
def __init__(self):
super().__init__('<PROVIDER_ID>', ProviderConfigForClient(
client_id='<CLIENT_ID>',
))

async def get_user_info(self, oauth_tokens: Dict[str, Any], user_context: Dict[str, Any]) -> UserInfo:
def override_custom_provider(provider: Provider) -> Provider:
async def get_user_info(oauth_tokens: Dict[str, Any], user_context: Dict[str, Any]) -> UserInfo:
return UserInfo(
third_party_user_id="...",
email=UserInfoEmail(
Expand All @@ -633,9 +629,9 @@ class CustomProvider(Provider):
},
),
)
provider.get_user_info = get_user_info
return provider

def get_custom_provider(provider: Provider) -> Provider:
return CustomProvider()

init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
Expand Down Expand Up @@ -665,7 +661,7 @@ init(
},
token_endpoint="https://example.com/oauth/token",
),
override=get_custom_provider
override=override_custom_provider
),
]
^{pythonSignInUpFeatureEnd}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,13 +612,9 @@ from supertokens_python.recipe.thirdparty.provider import ProviderClientConfig,
from supertokens_python.recipe.thirdparty.types import UserInfo, UserInfoEmail, RawUserInfoFromProvider
from typing import Dict, Any

class CustomProvider(Provider):
def __init__(self):
super().__init__('<PROVIDER_ID>', ProviderConfigForClient(
client_id='<CLIENT_ID>',
))

async def get_user_info(self, oauth_tokens: Dict[str, Any], user_context: Dict[str, Any]) -> UserInfo:
def override_custom_provider(provider: Provider) -> Provider:
async def get_user_info(oauth_tokens: Dict[str, Any], user_context: Dict[str, Any]) -> UserInfo:
return UserInfo(
third_party_user_id="...",
email=UserInfoEmail(
Expand All @@ -633,9 +629,9 @@ class CustomProvider(Provider):
},
),
)
provider.get_user_info = get_user_info
return provider

def get_custom_provider(provider: Provider) -> Provider:
return CustomProvider()

init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
Expand Down Expand Up @@ -665,7 +661,7 @@ init(
},
token_endpoint="https://example.com/oauth/token",
),
override=get_custom_provider
override=override_custom_provider
),
]
^{pythonSignInUpFeatureEnd}
Expand Down

0 comments on commit 4f59db3

Please sign in to comment.