square-administration 2.2.0__py3-none-any.whl → 2.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- square_administration/configuration.py +1 -0
- square_administration/data/config.ini +2 -0
- square_administration/main.py +2 -5
- square_administration/routes/authentication.py +52 -0
- square_administration/utils/common.py +12 -0
- {square_administration-2.2.0.dist-info → square_administration-2.3.0.dist-info}/METADATA +15 -1
- {square_administration-2.2.0.dist-info → square_administration-2.3.0.dist-info}/RECORD +9 -8
- {square_administration-2.2.0.dist-info → square_administration-2.3.0.dist-info}/WHEEL +0 -0
- {square_administration-2.2.0.dist-info → square_administration-2.3.0.dist-info}/top_level.txt +0 -0
@@ -42,6 +42,7 @@ try:
|
|
42
42
|
config_str_ssl_key_file_path = ldict_configuration["ENVIRONMENT"][
|
43
43
|
"SSL_KEY_FILE_PATH"
|
44
44
|
]
|
45
|
+
config_str_cookie_domain = ldict_configuration["ENVIRONMENT"]["COOKIE_DOMAIN"]
|
45
46
|
# ===========================================
|
46
47
|
|
47
48
|
# ===========================================
|
square_administration/main.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
import os.path
|
2
|
-
|
3
1
|
from fastapi import FastAPI, status
|
4
2
|
from fastapi.middleware.cors import CORSMiddleware
|
5
3
|
from fastapi.responses import JSONResponse
|
@@ -15,6 +13,7 @@ from square_administration.configuration import (
|
|
15
13
|
config_str_ssl_crt_file_path,
|
16
14
|
)
|
17
15
|
from square_administration.routes import core, authentication
|
16
|
+
from square_administration.utils.common import is_https
|
18
17
|
|
19
18
|
app = FastAPI()
|
20
19
|
|
@@ -39,9 +38,7 @@ async def root():
|
|
39
38
|
|
40
39
|
if __name__ == "__main__":
|
41
40
|
try:
|
42
|
-
if
|
43
|
-
config_str_ssl_crt_file_path
|
44
|
-
):
|
41
|
+
if is_https():
|
45
42
|
run(
|
46
43
|
app,
|
47
44
|
host=config_str_host_ip,
|
@@ -1,10 +1,12 @@
|
|
1
1
|
import json
|
2
|
+
from datetime import datetime
|
2
3
|
from typing import Annotated
|
3
4
|
|
4
5
|
import bcrypt
|
5
6
|
from fastapi import APIRouter, status, HTTPException, Header, Request
|
6
7
|
from fastapi.responses import JSONResponse
|
7
8
|
from requests import HTTPError
|
9
|
+
from square_authentication_helper import TokenType
|
8
10
|
from square_commons import get_api_output_in_standard_format
|
9
11
|
from square_commons.api_utils import create_cookie
|
10
12
|
|
@@ -13,12 +15,14 @@ from square_administration.configuration import (
|
|
13
15
|
config_str_admin_password_hash,
|
14
16
|
global_object_square_authentication_helper,
|
15
17
|
global_int_app_id,
|
18
|
+
config_str_cookie_domain,
|
16
19
|
)
|
17
20
|
from square_administration.messages import messages
|
18
21
|
from square_administration.pydantic_models.authentication import (
|
19
22
|
RegisterUsernameV0,
|
20
23
|
LoginUsernameV0,
|
21
24
|
)
|
25
|
+
from square_administration.utils.common import is_https
|
22
26
|
|
23
27
|
router = APIRouter(
|
24
28
|
tags=["authentication"],
|
@@ -68,7 +72,11 @@ async def register_username_v0(
|
|
68
72
|
return value
|
69
73
|
"""
|
70
74
|
refresh_token = response["data"]["main"]["refresh_token"]
|
75
|
+
refresh_token_expiry_time = response["data"]["main"][
|
76
|
+
"refresh_token_expiry_time"
|
77
|
+
]
|
71
78
|
del response["data"]["main"]["refresh_token"]
|
79
|
+
del response["data"]["main"]["refresh_token_expiry_time"]
|
72
80
|
output_content = get_api_output_in_standard_format(
|
73
81
|
message=messages["REGISTRATION_SUCCESSFUL"],
|
74
82
|
data={"main": response["data"]["main"]},
|
@@ -81,6 +89,10 @@ async def register_username_v0(
|
|
81
89
|
**create_cookie(
|
82
90
|
key="refresh_token|" + str(global_int_app_id),
|
83
91
|
value=refresh_token,
|
92
|
+
domain=config_str_cookie_domain,
|
93
|
+
expires=datetime.fromisoformat(refresh_token_expiry_time),
|
94
|
+
secure=is_https(),
|
95
|
+
http_only=True,
|
84
96
|
)
|
85
97
|
)
|
86
98
|
return json_response
|
@@ -144,7 +156,11 @@ async def login_username_v0(
|
|
144
156
|
return value
|
145
157
|
"""
|
146
158
|
refresh_token = response["data"]["main"]["refresh_token"]
|
159
|
+
refresh_token_expiry_time = response["data"]["main"][
|
160
|
+
"refresh_token_expiry_time"
|
161
|
+
]
|
147
162
|
del response["data"]["main"]["refresh_token"]
|
163
|
+
del response["data"]["main"]["refresh_token_expiry_time"]
|
148
164
|
output_content = get_api_output_in_standard_format(
|
149
165
|
message=messages["LOGIN_SUCCESSFUL"],
|
150
166
|
data={"main": response["data"]["main"]},
|
@@ -157,6 +173,10 @@ async def login_username_v0(
|
|
157
173
|
**create_cookie(
|
158
174
|
key="refresh_token|" + str(global_int_app_id),
|
159
175
|
value=refresh_token,
|
176
|
+
domain=config_str_cookie_domain,
|
177
|
+
expires=datetime.fromisoformat(refresh_token_expiry_time),
|
178
|
+
secure=is_https(),
|
179
|
+
http_only=True,
|
160
180
|
)
|
161
181
|
)
|
162
182
|
return json_response
|
@@ -277,6 +297,22 @@ async def logout_v0(request: Request):
|
|
277
297
|
status_code=status.HTTP_400_BAD_REQUEST,
|
278
298
|
content=output_content,
|
279
299
|
)
|
300
|
+
refresh_token_payload = global_object_square_authentication_helper.validate_and_get_payload_from_token_v0(
|
301
|
+
refresh_token, TokenType.refresh_token
|
302
|
+
)[
|
303
|
+
"data"
|
304
|
+
][
|
305
|
+
"main"
|
306
|
+
]
|
307
|
+
if refresh_token_payload["app_id"] != global_int_app_id:
|
308
|
+
output_content = get_api_output_in_standard_format(
|
309
|
+
message=messages["INCORRECT_REFRESH_TOKEN"],
|
310
|
+
log=f"refresh token is for different app id. intended app id: {global_int_app_id}, actual app id: {refresh_token_payload['app_id']}.",
|
311
|
+
)
|
312
|
+
return JSONResponse(
|
313
|
+
status_code=status.HTTP_400_BAD_REQUEST,
|
314
|
+
content=output_content,
|
315
|
+
)
|
280
316
|
"""
|
281
317
|
main process
|
282
318
|
"""
|
@@ -345,6 +381,22 @@ async def generate_access_token_v0(
|
|
345
381
|
status_code=status.HTTP_400_BAD_REQUEST,
|
346
382
|
content=output_content,
|
347
383
|
)
|
384
|
+
refresh_token_payload = global_object_square_authentication_helper.validate_and_get_payload_from_token_v0(
|
385
|
+
refresh_token, TokenType.refresh_token
|
386
|
+
)[
|
387
|
+
"data"
|
388
|
+
][
|
389
|
+
"main"
|
390
|
+
]
|
391
|
+
if refresh_token_payload["app_id"] != global_int_app_id:
|
392
|
+
output_content = get_api_output_in_standard_format(
|
393
|
+
message=messages["INCORRECT_REFRESH_TOKEN"],
|
394
|
+
log=f"refresh token is for different app id. intended app id: {global_int_app_id}, actual app id: {refresh_token_payload['app_id']}.",
|
395
|
+
)
|
396
|
+
return JSONResponse(
|
397
|
+
status_code=status.HTTP_400_BAD_REQUEST,
|
398
|
+
content=output_content,
|
399
|
+
)
|
348
400
|
"""
|
349
401
|
main process
|
350
402
|
"""
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from square_administration.configuration import (
|
4
|
+
config_str_ssl_key_file_path,
|
5
|
+
config_str_ssl_crt_file_path,
|
6
|
+
)
|
7
|
+
|
8
|
+
|
9
|
+
def is_https() -> bool:
|
10
|
+
return os.path.exists(config_str_ssl_key_file_path) and os.path.exists(
|
11
|
+
config_str_ssl_crt_file_path
|
12
|
+
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: square-administration
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.3.0
|
4
4
|
Summary: common business layer for my personal server.
|
5
5
|
Home-page: https://github.com/thepmsquare/square_administration
|
6
6
|
Author: thePmSquare
|
@@ -42,6 +42,20 @@ pip install square_administration
|
|
42
42
|
|
43
43
|
## changelog
|
44
44
|
|
45
|
+
### v2.3.0
|
46
|
+
|
47
|
+
- env
|
48
|
+
- add new variable COOKIE_DOMAIN.
|
49
|
+
- util
|
50
|
+
- add is_https.
|
51
|
+
- authentication
|
52
|
+
- add domain, exp_time, secure and http_only flags for cookies generated in login_username_v0, register_username_v0.
|
53
|
+
|
54
|
+
### v2.2.1
|
55
|
+
|
56
|
+
- authentication
|
57
|
+
- add validation for refresh token app id in logout_v0, generate_access_token_v0.
|
58
|
+
|
45
59
|
### v2.2.0
|
46
60
|
|
47
61
|
- authentication
|
@@ -1,16 +1,17 @@
|
|
1
1
|
square_administration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
square_administration/configuration.py,sha256=
|
3
|
-
square_administration/main.py,sha256=
|
2
|
+
square_administration/configuration.py,sha256=k4ZxGB-RBvHLWQ5ksv-fj0UfAXJ25bSNu5uLNn_rnVc,4816
|
3
|
+
square_administration/main.py,sha256=YHala3fQjbj4wQuIzCWEZ3xeeVsidPLHabCUsADr4tE,1613
|
4
4
|
square_administration/messages.py,sha256=VYjJGW0Kvtjrx1Mw7ekksLVMoxcexLol2OckvqhZ3n0,1063
|
5
|
-
square_administration/data/config.ini,sha256=
|
5
|
+
square_administration/data/config.ini,sha256=sTWBnaNGXqLi0Ckk2cNzBC7pqrlboyU_ClLl04luOZY,1024
|
6
6
|
square_administration/pydantic_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
square_administration/pydantic_models/authentication.py,sha256=DWXctw5UWzkSVY7nMIQZsRhmgW3OK455OVcoUpJrPY0,202
|
8
8
|
square_administration/pydantic_models/core.py,sha256=HUMrBmfKrXeL-126gE5j2povdVmktn8XLg2tHEdeXTk,344
|
9
9
|
square_administration/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
square_administration/routes/authentication.py,sha256=
|
10
|
+
square_administration/routes/authentication.py,sha256=wq1JFXVfbVEy3_HGdFVk2823YgMs8qhWl_gR6Cqv_ik,14237
|
11
11
|
square_administration/routes/core.py,sha256=65_FIZilintZvbHx7r25UQbgN-oKdQ92-Nv3kpwKX6s,5374
|
12
12
|
square_administration/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
-
square_administration
|
14
|
-
square_administration-2.
|
15
|
-
square_administration-2.
|
16
|
-
square_administration-2.
|
13
|
+
square_administration/utils/common.py,sha256=amCGhwizka1MgM-Xlw_8f07V54Br7pOvCDtevJfz98M,276
|
14
|
+
square_administration-2.3.0.dist-info/METADATA,sha256=Xv5LDFtx2fBxk7MI0e0_5z8aBCjdSNs6_ncGrrgB0mk,2024
|
15
|
+
square_administration-2.3.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
16
|
+
square_administration-2.3.0.dist-info/top_level.txt,sha256=8WFipDrMQUPRDo5AvipxU1YK3wZtWZyCUMWaR416zAw,22
|
17
|
+
square_administration-2.3.0.dist-info/RECORD,,
|
File without changes
|
{square_administration-2.2.0.dist-info → square_administration-2.3.0.dist-info}/top_level.txt
RENAMED
File without changes
|