Skip to content

Commit a56d486

Browse files
Merge pull request #754 from supertokens/python-app-info-refactor
Python app info refactor
2 parents daa9f5c + 382df4d commit a56d486

File tree

13 files changed

+206
-36
lines changed

13 files changed

+206
-36
lines changed

v2/emailpassword/advanced-customizations/user-context.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class EmptySession(session.SessionContainer):
408408
async def get_expiry(self, user_context: Union[Dict[str, Any], None] = None) -> int:
409409
return -1
410410

411-
async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod):
411+
async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod, user_context: Union[Dict[str, Any], None] = None):
412412
pass
413413

414414
async def assert_claims(

v2/emailpassword/common-customizations/multiple-clients.mdx

+37-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,43 @@ func main() {
119119
</TabItem>
120120
<TabItem value="python">
121121

122-
:::note
123-
Coming Soon
124-
:::
122+
```python
123+
from supertokens_python import init, InputAppInfo, SupertokensConfig
124+
from supertokens_python.framework.request import BaseRequest
125+
from typing import Optional, Dict, Any
126+
127+
128+
# highlight-start
129+
def get_origin(request: Optional[BaseRequest], user_context: Dict[str, Any]) -> str:
130+
if request is not None:
131+
origin = request.get_header("origin")
132+
if origin is None:
133+
# this means the client is in an iframe, it's a mobile app, or
134+
# there is a privacy setting on the frontend which doesn't send
135+
# the origin
136+
pass
137+
else:
138+
if origin == "https://test.example.com":
139+
# query from the test site
140+
return "https://test.example.com"
141+
elif origin == "http://localhost:3000":
142+
# query from local development
143+
return "http://localhost:3000"
144+
145+
# in case the origin is unknown or not set, we return a default
146+
# value which will be used for this request.
147+
return "https://test.example.com"
148+
# highlight-end
149+
150+
init(
151+
app_info=InputAppInfo(app_name="...", api_domain="...", origin=get_origin),
152+
supertokens_config=SupertokensConfig(connection_uri="...", api_key="..."),
153+
framework="fastapi", # works with other frameworks as well.
154+
recipe_list=[
155+
# ...
156+
],
157+
)
158+
```
125159

126160
</TabItem>
127161
</BackendSDKTabs>

v2/passwordless/advanced-customizations/user-context.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ class EmptySession(session.SessionContainer):
456456
async def get_expiry(self, user_context: Union[Dict[str, Any], None] = None) -> int:
457457
return -1
458458

459-
async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod):
459+
async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod, user_context: Union[Dict[str, Any], None] = None):
460460
pass
461461

462462
async def assert_claims(

v2/passwordless/common-customizations/multiple-clients.mdx

+37-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,43 @@ func main() {
119119
</TabItem>
120120
<TabItem value="python">
121121

122-
:::note
123-
Coming Soon
124-
:::
122+
```python
123+
from supertokens_python import init, InputAppInfo, SupertokensConfig
124+
from supertokens_python.framework.request import BaseRequest
125+
from typing import Optional, Dict, Any
126+
127+
128+
# highlight-start
129+
def get_origin(request: Optional[BaseRequest], user_context: Dict[str, Any]) -> str:
130+
if request is not None:
131+
origin = request.get_header("origin")
132+
if origin is None:
133+
# this means the client is in an iframe, it's a mobile app, or
134+
# there is a privacy setting on the frontend which doesn't send
135+
# the origin
136+
pass
137+
else:
138+
if origin == "https://test.example.com":
139+
# query from the test site
140+
return "https://test.example.com"
141+
elif origin == "http://localhost:3000":
142+
# query from local development
143+
return "http://localhost:3000"
144+
145+
# in case the origin is unknown or not set, we return a default
146+
# value which will be used for this request.
147+
return "https://test.example.com"
148+
# highlight-end
149+
150+
init(
151+
app_info=InputAppInfo(app_name="...", api_domain="...", origin=get_origin),
152+
supertokens_config=SupertokensConfig(connection_uri="...", api_key="..."),
153+
framework="fastapi", # works with other frameworks as well.
154+
recipe_list=[
155+
# ...
156+
],
157+
)
158+
```
125159

126160
</TabItem>
127161
</BackendSDKTabs>

v2/src/plugins/codeTypeChecking/goEnv/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/go-chi/cors v1.2.1
1010
github.com/gorilla/handlers v1.5.1
1111
github.com/gorilla/mux v1.8.0
12-
github.com/supertokens/supertokens-golang v0.17.1-0.20231125104805-1f08095a133e
12+
github.com/supertokens/supertokens-golang v0.17.1
1313
)
1414

1515
require (

v2/src/plugins/codeTypeChecking/goEnv/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
9595
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
9696
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
9797
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
98-
github.com/supertokens/supertokens-golang v0.17.1-0.20231125104805-1f08095a133e h1:esMJPRbqTHFZwCvW4hrOcaA/IXU/5psgRluk1mtak6k=
99-
github.com/supertokens/supertokens-golang v0.17.1-0.20231125104805-1f08095a133e/go.mod h1:/n6zQ9461RscnnWB4Y4bWwzhPivnj8w79j/doqkLOs8=
98+
github.com/supertokens/supertokens-golang v0.17.1 h1:uuYmYio7+T4HmrqyVfxUAmdMTcIsYRIBTod+h/DFW0Q=
99+
github.com/supertokens/supertokens-golang v0.17.1/go.mod h1:/n6zQ9461RscnnWB4Y4bWwzhPivnj8w79j/doqkLOs8=
100100
github.com/twilio/twilio-go v0.26.0 h1:wFW4oTe3/LKt6bvByP7eio8JsjtaLHjMQKOUEzQry7U=
101101
github.com/twilio/twilio-go v0.26.0/go.mod h1:lz62Hopu4vicpQ056H5TJ0JE4AP0rS3sQ35/ejmgOwE=
102102
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=

v2/src/plugins/codeTypeChecking/pythonEnv/requirements.txt

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
aiosmtplib==1.1.6
2-
anyio==3.7.1
2+
anyio==4.1.0
33
asgiref==3.7.2
44
astroid==2.9.3
55
attrs==21.4.0
66
autopep8==1.5.6
77
black==22.3.0
8-
certifi==2023.7.22
9-
cffi==1.15.1
8+
certifi==2023.11.17
9+
cffi==1.16.0
1010
chardet==4.0.0
11-
charset-normalizer==3.2.0
11+
charset-normalizer==3.3.2
1212
click==8.1.3
13-
cryptography==41.0.3
13+
cryptography==41.0.7
1414
Deprecated==1.2.13
1515
Django==3.2.12
1616
django-cors-headers==3.11.0
1717
django-stubs==1.9.0
1818
django-stubs-ext==0.4.0
19-
exceptiongroup==1.1.3
19+
exceptiongroup==1.2.0
2020
fastapi==0.68.1
21-
filelock==3.12.2
21+
filelock==3.13.1
2222
Flask==2.0.2
2323
Flask-Cors==3.0.10
2424
h11==0.14.0
2525
httpcore==0.17.3
2626
httpx==0.24.1
27-
idna==3.4
27+
idna==3.6
2828
importlib-metadata==4.11.3
2929
iniconfig==1.1.1
3030
isort==5.10.1
@@ -61,7 +61,7 @@ pyrsistent==0.18.1
6161
pytest==6.2.5
6262
pytest-asyncio==0.14.0
6363
python-dotenv==0.19.2
64-
pytz==2023.3
64+
pytz==2023.3.post1
6565
PyYAML==5.4.1
6666
requests==2.31.0
6767
requests-file==1.5.1
@@ -72,17 +72,17 @@ six==1.16.0
7272
sniffio==1.3.0
7373
sqlparse==0.4.2
7474
starlette==0.14.2
75-
supertokens-python==0.16.7
75+
supertokens-python==0.18.0
7676
tldextract==3.1.0
7777
toml==0.10.2
7878
tomli==2.0.1
7979
twilio==7.9.1
8080
types-pytz==2021.3.6
8181
types-PyYAML==6.0.5
82-
typing_extensions==4.7.1
82+
typing_extensions==4.8.0
8383
tzdata==2021.5
84-
urllib3==2.0.4
84+
urllib3==2.1.0
8585
uvicorn==0.18.2
8686
Werkzeug==2.0.3
87-
wrapt==1.13.0
87+
wrapt==1.16.0
8888
zipp==3.7.0

v2/thirdparty/advanced-customizations/user-context.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ class EmptySession(session.SessionContainer):
461461
async def get_expiry(self, user_context: Union[Dict[str, Any], None] = None) -> int:
462462
return -1
463463

464-
async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod):
464+
async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod, user_context: Union[Dict[str, Any], None] = None):
465465
pass
466466

467467
async def assert_claims(

v2/thirdparty/common-customizations/multiple-clients.mdx

+37-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,43 @@ func main() {
119119
</TabItem>
120120
<TabItem value="python">
121121

122-
:::note
123-
Coming Soon
124-
:::
122+
```python
123+
from supertokens_python import init, InputAppInfo, SupertokensConfig
124+
from supertokens_python.framework.request import BaseRequest
125+
from typing import Optional, Dict, Any
126+
127+
128+
# highlight-start
129+
def get_origin(request: Optional[BaseRequest], user_context: Dict[str, Any]) -> str:
130+
if request is not None:
131+
origin = request.get_header("origin")
132+
if origin is None:
133+
# this means the client is in an iframe, it's a mobile app, or
134+
# there is a privacy setting on the frontend which doesn't send
135+
# the origin
136+
pass
137+
else:
138+
if origin == "https://test.example.com":
139+
# query from the test site
140+
return "https://test.example.com"
141+
elif origin == "http://localhost:3000":
142+
# query from local development
143+
return "http://localhost:3000"
144+
145+
# in case the origin is unknown or not set, we return a default
146+
# value which will be used for this request.
147+
return "https://test.example.com"
148+
# highlight-end
149+
150+
init(
151+
app_info=InputAppInfo(app_name="...", api_domain="...", origin=get_origin),
152+
supertokens_config=SupertokensConfig(connection_uri="...", api_key="..."),
153+
framework="fastapi", # works with other frameworks as well.
154+
recipe_list=[
155+
# ...
156+
],
157+
)
158+
```
125159

126160
</TabItem>
127161
</BackendSDKTabs>

v2/thirdpartyemailpassword/advanced-customizations/user-context.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ class EmptySession(session.SessionContainer):
483483
async def get_expiry(self, user_context: Union[Dict[str, Any], None] = None) -> int:
484484
return -1
485485

486-
async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod):
486+
async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod, user_context: Union[Dict[str, Any], None] = None):
487487
pass
488488

489489
async def assert_claims(

v2/thirdpartyemailpassword/common-customizations/multiple-clients.mdx

+37-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,43 @@ func main() {
119119
</TabItem>
120120
<TabItem value="python">
121121

122-
:::note
123-
Coming Soon
124-
:::
122+
```python
123+
from supertokens_python import init, InputAppInfo, SupertokensConfig
124+
from supertokens_python.framework.request import BaseRequest
125+
from typing import Optional, Dict, Any
126+
127+
128+
# highlight-start
129+
def get_origin(request: Optional[BaseRequest], user_context: Dict[str, Any]) -> str:
130+
if request is not None:
131+
origin = request.get_header("origin")
132+
if origin is None:
133+
# this means the client is in an iframe, it's a mobile app, or
134+
# there is a privacy setting on the frontend which doesn't send
135+
# the origin
136+
pass
137+
else:
138+
if origin == "https://test.example.com":
139+
# query from the test site
140+
return "https://test.example.com"
141+
elif origin == "http://localhost:3000":
142+
# query from local development
143+
return "http://localhost:3000"
144+
145+
# in case the origin is unknown or not set, we return a default
146+
# value which will be used for this request.
147+
return "https://test.example.com"
148+
# highlight-end
149+
150+
init(
151+
app_info=InputAppInfo(app_name="...", api_domain="...", origin=get_origin),
152+
supertokens_config=SupertokensConfig(connection_uri="...", api_key="..."),
153+
framework="fastapi", # works with other frameworks as well.
154+
recipe_list=[
155+
# ...
156+
],
157+
)
158+
```
125159

126160
</TabItem>
127161
</BackendSDKTabs>

v2/thirdpartypasswordless/advanced-customizations/user-context.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ class EmptySession(session.SessionContainer):
525525
async def get_expiry(self, user_context: Union[Dict[str, Any], None] = None) -> int:
526526
return -1
527527

528-
async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod):
528+
async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod, user_context: Union[Dict[str, Any], None] = None):
529529
pass
530530

531531
async def assert_claims(

v2/thirdpartypasswordless/common-customizations/multiple-clients.mdx

+37-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,43 @@ func main() {
119119
</TabItem>
120120
<TabItem value="python">
121121

122-
:::note
123-
Coming Soon
124-
:::
122+
```python
123+
from supertokens_python import init, InputAppInfo, SupertokensConfig
124+
from supertokens_python.framework.request import BaseRequest
125+
from typing import Optional, Dict, Any
126+
127+
128+
# highlight-start
129+
def get_origin(request: Optional[BaseRequest], user_context: Dict[str, Any]) -> str:
130+
if request is not None:
131+
origin = request.get_header("origin")
132+
if origin is None:
133+
# this means the client is in an iframe, it's a mobile app, or
134+
# there is a privacy setting on the frontend which doesn't send
135+
# the origin
136+
pass
137+
else:
138+
if origin == "https://test.example.com":
139+
# query from the test site
140+
return "https://test.example.com"
141+
elif origin == "http://localhost:3000":
142+
# query from local development
143+
return "http://localhost:3000"
144+
145+
# in case the origin is unknown or not set, we return a default
146+
# value which will be used for this request.
147+
return "https://test.example.com"
148+
# highlight-end
149+
150+
init(
151+
app_info=InputAppInfo(app_name="...", api_domain="...", origin=get_origin),
152+
supertokens_config=SupertokensConfig(connection_uri="...", api_key="..."),
153+
framework="fastapi", # works with other frameworks as well.
154+
recipe_list=[
155+
# ...
156+
],
157+
)
158+
```
125159

126160
</TabItem>
127161
</BackendSDKTabs>

0 commit comments

Comments
 (0)