square-administration 2.2.1__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.
@@ -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
  # ===========================================
@@ -14,6 +14,8 @@ ADMIN_PASSWORD_HASH = $2b$12$tDw4ZR0guiF5s5oVve5PcuELhlWO.lUH.OChPoeWVn95ac7QJln
14
14
  SSL_CRT_FILE_PATH = ssl.crt
15
15
  SSL_KEY_FILE_PATH = ssl.key
16
16
 
17
+ COOKIE_DOMAIN = localhost
18
+
17
19
  [SQUARE_LOGGER]
18
20
 
19
21
  # | Log Level | Value |
@@ -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 os.path.exists(config_str_ssl_key_file_path) and os.path.exists(
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,4 +1,5 @@
1
1
  import json
2
+ from datetime import datetime
2
3
  from typing import Annotated
3
4
 
4
5
  import bcrypt
@@ -14,12 +15,14 @@ from square_administration.configuration import (
14
15
  config_str_admin_password_hash,
15
16
  global_object_square_authentication_helper,
16
17
  global_int_app_id,
18
+ config_str_cookie_domain,
17
19
  )
18
20
  from square_administration.messages import messages
19
21
  from square_administration.pydantic_models.authentication import (
20
22
  RegisterUsernameV0,
21
23
  LoginUsernameV0,
22
24
  )
25
+ from square_administration.utils.common import is_https
23
26
 
24
27
  router = APIRouter(
25
28
  tags=["authentication"],
@@ -69,7 +72,11 @@ async def register_username_v0(
69
72
  return value
70
73
  """
71
74
  refresh_token = response["data"]["main"]["refresh_token"]
75
+ refresh_token_expiry_time = response["data"]["main"][
76
+ "refresh_token_expiry_time"
77
+ ]
72
78
  del response["data"]["main"]["refresh_token"]
79
+ del response["data"]["main"]["refresh_token_expiry_time"]
73
80
  output_content = get_api_output_in_standard_format(
74
81
  message=messages["REGISTRATION_SUCCESSFUL"],
75
82
  data={"main": response["data"]["main"]},
@@ -82,6 +89,10 @@ async def register_username_v0(
82
89
  **create_cookie(
83
90
  key="refresh_token|" + str(global_int_app_id),
84
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,
85
96
  )
86
97
  )
87
98
  return json_response
@@ -145,7 +156,11 @@ async def login_username_v0(
145
156
  return value
146
157
  """
147
158
  refresh_token = response["data"]["main"]["refresh_token"]
159
+ refresh_token_expiry_time = response["data"]["main"][
160
+ "refresh_token_expiry_time"
161
+ ]
148
162
  del response["data"]["main"]["refresh_token"]
163
+ del response["data"]["main"]["refresh_token_expiry_time"]
149
164
  output_content = get_api_output_in_standard_format(
150
165
  message=messages["LOGIN_SUCCESSFUL"],
151
166
  data={"main": response["data"]["main"]},
@@ -158,6 +173,10 @@ async def login_username_v0(
158
173
  **create_cookie(
159
174
  key="refresh_token|" + str(global_int_app_id),
160
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,
161
180
  )
162
181
  )
163
182
  return json_response
@@ -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.2.1
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,15 @@ 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
+
45
54
  ### v2.2.1
46
55
 
47
56
  - authentication
@@ -1,16 +1,17 @@
1
1
  square_administration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- square_administration/configuration.py,sha256=ldSmVp3FWOndN4u-dH-pf4i0olRZx1-uORJAj1qW-g8,4733
3
- square_administration/main.py,sha256=L4MM_7yimRLB8J1ltgXPnrN3j_UXKVtp8o8S46MSqrY,1678
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=NMpUnBSPEdwCW1Y-z5DOjpTQgXGjt4ZcqP4QQiAXr_U,997
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=V1NZgee3IvQNzCjP4TdVDc-7sWNd2m7EjG1d3m-C7Yw,13383
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-2.2.1.dist-info/METADATA,sha256=ygKKKDOhbGQUhkk2Caj2RfxtHB559qM43Q7VQoubMzk,1802
14
- square_administration-2.2.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
15
- square_administration-2.2.1.dist-info/top_level.txt,sha256=8WFipDrMQUPRDo5AvipxU1YK3wZtWZyCUMWaR416zAw,22
16
- square_administration-2.2.1.dist-info/RECORD,,
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,,