Skip to content

Commit 6295c4b

Browse files
Merge pull request #459 from supertokens/feat/appinfo-refactor
feat!: appinfo refactor
2 parents 3529bb4 + b9d007c commit 6295c4b

File tree

53 files changed

+915
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+915
-188
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
},
77
"python.analysis.typeCheckingMode": "strict",
88
"python.testing.unittestEnabled": false,
9-
"python.testing.pytestEnabled": true
9+
"python.testing.pytestEnabled": true,
10+
"python.analysis.autoImportCompletions": true
1011
}

CHANGELOG.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,49 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [unreleased]
1010

11+
## [0.18.0] - 2023-11-25
12+
13+
### Added
14+
15+
- Adds support for configuring multiple frontend domains to be used with the same backend
16+
- Added new `origin` property to `InputAppInfo`, this can be configured to allow you to conditionally return the value of the frontend domain. This property will replace `website_domain`
17+
- `website_domain` inside `InputAppInfo` is now optional. Using `origin` recommended over using `website_domain`. Using `website_domain` will continue to work.
18+
19+
### Breaking Change
20+
- The order or arguments in the `InputAppInfo` has changed. If NOT using keyword arguments for `app_info` in `supertokens.init`, then you will have to move `website_domain` like so:
21+
22+
Before:
23+
```python
24+
init(
25+
app_info=InputAppInfo(
26+
"app_name",
27+
"api_domain",
28+
"website_domain",
29+
None, # api_gateway_path
30+
None, # api_base_path
31+
None, # website_base_path
32+
),
33+
# other configs..
34+
)
35+
```
36+
37+
After:
38+
```python
39+
init(
40+
app_info=InputAppInfo(
41+
"app_name",
42+
"api_domain",
43+
None, # api_gateway_path
44+
None, # api_base_path
45+
None, # website_base_path
46+
"website_domain"
47+
),
48+
# other configs..
49+
)
50+
```
51+
52+
- In the session recipe, if there is an `UNAUTHORISED` or `TOKEN_THEFT_DETECTED` error, the session tokens are cleared in the response regardless of if you have provided your own `error_handlers` in `session.init`
53+
1154
## [0.17.0] - 2023-11-14
1255
- Fixes `create_reset_password_link` in the emailpassword recipe wherein we passed the `rid` instead of the token in the link
1356

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ You will need to setup the [supertokens-core](https://github.com/supertokens/sup
4747
3. Open a new terminal and navigate to the `supertokens-python` respositry.
4848
4. Use `export SUPERTOKENS_PATH=path/to/supertokens-root` (**MANDATORY**)
4949
4. To run all tests, while ensuring the test environment is running on a different terminal, use `make test`.
50-
5. To run individual tests, use `pytest ./tests/path/to/test/file.py -k test_function_name` OR use your IDE's in-built UI for running python tests. You may read [VSCode Python Testing](https://code.visualstudio.com/docs/python/testing) and [PyCharm Testing](https://www.jetbrains.com/help/pycharm/testing-your-first-python-application.html#debug-test) for more info.
50+
5. To run individual tests, use `INSTALL_DIR=../supertokens-root pytest ./tests/path/to/test/file.py::test_function_name` OR use your IDE's in-built UI for running python tests. You may read [VSCode Python Testing](https://code.visualstudio.com/docs/python/testing) and [PyCharm Testing](https://www.jetbrains.com/help/pycharm/testing-your-first-python-application.html#debug-test) for more info.
5151

5252
## Pull Request
5353

examples/with-django/with-thirdpartyemailpassword/create_env.sh

100644100755
File mode changed.

examples/with-fastapi/with-thirdpartyemailpassword/create_env.sh

100644100755
File mode changed.

examples/with-flask/with-thirdpartyemailpassword/create_env.sh

100644100755
File mode changed.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
setup(
7272
name="supertokens_python",
73-
version="0.17.0",
73+
version="0.18.0",
7474
author="SuperTokens",
7575
license="Apache 2.0",
7676
author_email="[email protected]",

supertokens_python/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from __future__ import annotations
1515

1616
SUPPORTED_CDI_VERSIONS = ["3.0"]
17-
VERSION = "0.17.0"
17+
VERSION = "0.18.0"
1818
TELEMETRY = "/telemetry"
1919
USER_COUNT = "/users/count"
2020
USER_DELETE = "/user/remove"

supertokens_python/framework/django/django_middleware.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ async def __asyncMiddleware(request: HttpRequest):
4949
request.supertokens, SessionContainer # type: ignore
5050
):
5151
manage_session_post_response(
52-
request.supertokens, result # type: ignore
52+
request.supertokens, result, user_context # type: ignore
5353
)
5454
if isinstance(result, DjangoResponse):
5555
return result.response
5656
except SuperTokensError as e:
5757
response = DjangoResponse(HttpResponse())
5858
result = await st.handle_supertokens_error(
59-
DjangoRequest(request), e, response
59+
DjangoRequest(request), e, response, user_context
6060
)
6161
if isinstance(result, DjangoResponse):
6262
return result.response
@@ -85,15 +85,15 @@ def __syncMiddleware(request: HttpRequest):
8585
request.supertokens, SessionContainer # type: ignore
8686
):
8787
manage_session_post_response(
88-
request.supertokens, result # type: ignore
88+
request.supertokens, result, user_context # type: ignore
8989
)
9090
return result.response
9191

9292
except SuperTokensError as e:
9393
response = DjangoResponse(HttpResponse())
9494
result: Union[DjangoResponse, None] = async_to_sync(
9595
st.handle_supertokens_error
96-
)(DjangoRequest(request), e, response)
96+
)(DjangoRequest(request), e, response, user_context)
9797
if result is not None:
9898
return result.response
9999
raise Exception("Should never come here")

supertokens_python/framework/fastapi/fastapi_middleware.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint):
4444
st = Supertokens.get_instance()
4545
from fastapi.responses import Response
4646

47+
custom_request = FastApiRequest(request)
48+
response = FastApiResponse(Response())
49+
user_context = default_user_context(custom_request)
50+
4751
try:
48-
custom_request = FastApiRequest(request)
49-
response = FastApiResponse(Response())
50-
user_context = default_user_context(custom_request)
5152
result: Union[BaseResponse, None] = await st.middleware(
5253
custom_request, response, user_context
5354
)
@@ -58,13 +59,15 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint):
5859
if hasattr(request.state, "supertokens") and isinstance(
5960
request.state.supertokens, SessionContainer
6061
):
61-
manage_session_post_response(request.state.supertokens, result)
62+
manage_session_post_response(
63+
request.state.supertokens, result, user_context
64+
)
6265
if isinstance(result, FastApiResponse):
6366
return result.response
6467
except SuperTokensError as e:
6568
response = FastApiResponse(Response())
6669
result: Union[BaseResponse, None] = await st.handle_supertokens_error(
67-
FastApiRequest(request), e, response
70+
FastApiRequest(request), e, response, user_context
6871
)
6972
if isinstance(result, FastApiResponse):
7073
return result.response

0 commit comments

Comments
 (0)