Skip to content

Commit

Permalink
Merge pull request #726 from supertokens/apple-fixes
Browse files Browse the repository at this point in the history
Fix python snippets for apple login
  • Loading branch information
rishabhpoddar authored Oct 4, 2023
2 parents 20ef438 + c603fdf commit 09093af
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 42 deletions.
22 changes: 8 additions & 14 deletions v2/thirdparty/custom-ui/thirdparty-login.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -524,28 +524,26 @@ func main() {

```python
from supertokens_python.recipe import ^{codeImportRecipeName}
from supertokens_python.recipe.^{codeImportRecipeName}.interfaces import APIInterface, APIOptions
from typing import Union, Dict, Any
from supertokens_python.recipe.thirdparty.provider import Provider, RedirectUriInfo
from supertokens_python.recipe.^{codeImportRecipeName}.interfaces import APIInterface, ^{pythonThirdPartyAPIOptions}
from typing import Dict, Any

# highlight-start
def override_thirdparty_apis(original_implementation: APIInterface):
original_apple_redirect_post = original_implementation.apple_redirect_handler_post

async def apple_redirect_handler_post(
form_post_info: Dict[str, Any],
api_options: APIOptions,
api_options: ^{pythonThirdPartyAPIOptions},
user_context: Dict[str, Any]
):
# form_post_info contains all the query params attached by Apple
state = form_post_info["state"]

# The web SDKs add a default state
if state is None:
query_items = []

for key, value in form_post_info.items():
query_items.append(f"{key}={value}")
query_items = [
f"{key}={value}" for key, value in form_post_info.items()
]

query_string = "&".join(query_items)

Expand All @@ -556,7 +554,7 @@ def override_thirdparty_apis(original_implementation: APIInterface):
api_options.response.set_status_code(303)
api_options.response.set_html_content("")
else:
return original_apple_redirect_post(form_post_info, api_options, user_context)
return await original_apple_redirect_post(form_post_info, api_options, user_context)

original_implementation.apple_redirect_handler_post = apple_redirect_handler_post
return original_implementation
Expand All @@ -568,11 +566,7 @@ def override_thirdparty_apis(original_implementation: APIInterface):
apis=override_thirdparty_apis
),
# highlight-end
^{pythonSignInUpFeatureStart}
providers=[
# ...
]
^{pythonSignInUpFeatureEnd}
^{pythonRecipeInitDefault}
)
```

Expand Down
22 changes: 8 additions & 14 deletions v2/thirdpartyemailpassword/custom-ui/thirdparty-login.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -527,28 +527,26 @@ func main() {

```python
from supertokens_python.recipe import ^{codeImportRecipeName}
from supertokens_python.recipe.^{codeImportRecipeName}.interfaces import APIInterface, APIOptions
from typing import Union, Dict, Any
from supertokens_python.recipe.thirdparty.provider import Provider, RedirectUriInfo
from supertokens_python.recipe.^{codeImportRecipeName}.interfaces import APIInterface, ^{pythonThirdPartyAPIOptions}
from typing import Dict, Any

# highlight-start
def override_thirdparty_apis(original_implementation: APIInterface):
original_apple_redirect_post = original_implementation.apple_redirect_handler_post

async def apple_redirect_handler_post(
form_post_info: Dict[str, Any],
api_options: APIOptions,
api_options: ^{pythonThirdPartyAPIOptions},
user_context: Dict[str, Any]
):
# form_post_info contains all the query params attached by Apple
state = form_post_info["state"]

# The web SDKs add a default state
if state is None:
query_items = []

for key, value in form_post_info.items():
query_items.append(f"{key}={value}")
query_items = [
f"{key}={value}" for key, value in form_post_info.items()
]

query_string = "&".join(query_items)

Expand All @@ -559,7 +557,7 @@ def override_thirdparty_apis(original_implementation: APIInterface):
api_options.response.set_status_code(303)
api_options.response.set_html_content("")
else:
return original_apple_redirect_post(form_post_info, api_options, user_context)
return await original_apple_redirect_post(form_post_info, api_options, user_context)

original_implementation.apple_redirect_handler_post = apple_redirect_handler_post
return original_implementation
Expand All @@ -571,11 +569,7 @@ def override_thirdparty_apis(original_implementation: APIInterface):
apis=override_thirdparty_apis
),
# highlight-end
^{pythonSignInUpFeatureStart}
providers=[
# ...
]
^{pythonSignInUpFeatureEnd}
^{pythonRecipeInitDefault}
)
```

Expand Down
22 changes: 8 additions & 14 deletions v2/thirdpartypasswordless/custom-ui/thirdparty-login.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -527,28 +527,26 @@ func main() {

```python
from supertokens_python.recipe import ^{codeImportRecipeName}
from supertokens_python.recipe.^{codeImportRecipeName}.interfaces import APIInterface, APIOptions
from typing import Union, Dict, Any
from supertokens_python.recipe.thirdparty.provider import Provider, RedirectUriInfo
from supertokens_python.recipe.^{codeImportRecipeName}.interfaces import APIInterface, ^{pythonThirdPartyAPIOptions}
from typing import Dict, Any

# highlight-start
def override_thirdparty_apis(original_implementation: APIInterface):
original_apple_redirect_post = original_implementation.apple_redirect_handler_post

async def apple_redirect_handler_post(
form_post_info: Dict[str, Any],
api_options: APIOptions,
api_options: ^{pythonThirdPartyAPIOptions},
user_context: Dict[str, Any]
):
# form_post_info contains all the query params attached by Apple
state = form_post_info["state"]

# The web SDKs add a default state
if state is None:
query_items = []

for key, value in form_post_info.items():
query_items.append(f"{key}={value}")
query_items = [
f"{key}={value}" for key, value in form_post_info.items()
]

query_string = "&".join(query_items)

Expand All @@ -559,7 +557,7 @@ def override_thirdparty_apis(original_implementation: APIInterface):
api_options.response.set_status_code(303)
api_options.response.set_html_content("")
else:
return original_apple_redirect_post(form_post_info, api_options, user_context)
return await original_apple_redirect_post(form_post_info, api_options, user_context)

original_implementation.apple_redirect_handler_post = apple_redirect_handler_post
return original_implementation
Expand All @@ -571,11 +569,7 @@ def override_thirdparty_apis(original_implementation: APIInterface):
apis=override_thirdparty_apis
),
# highlight-end
^{pythonSignInUpFeatureStart}
providers=[
# ...
]
^{pythonSignInUpFeatureEnd}
^{pythonRecipeInitDefault}
)
```

Expand Down

0 comments on commit 09093af

Please sign in to comment.