square-authentication 5.1.0__tar.gz → 5.1.2__tar.gz

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.
Files changed (22) hide show
  1. {square_authentication-5.1.0 → square_authentication-5.1.2}/PKG-INFO +12 -1
  2. {square_authentication-5.1.0 → square_authentication-5.1.2}/README.md +11 -1
  3. {square_authentication-5.1.0 → square_authentication-5.1.2}/setup.py +2 -2
  4. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/routes/core.py +138 -121
  5. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/utils/encryption.py +4 -1
  6. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/utils/token.py +3 -0
  7. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication.egg-info/PKG-INFO +12 -1
  8. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication.egg-info/requires.txt +1 -1
  9. {square_authentication-5.1.0 → square_authentication-5.1.2}/setup.cfg +0 -0
  10. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/__init__.py +0 -0
  11. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/configuration.py +0 -0
  12. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/data/config.ini +0 -0
  13. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/main.py +0 -0
  14. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/messages.py +0 -0
  15. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/pydantic_models/__init__.py +0 -0
  16. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/pydantic_models/core.py +0 -0
  17. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/routes/__init__.py +0 -0
  18. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/routes/utility.py +0 -0
  19. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication/utils/__init__.py +0 -0
  20. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication.egg-info/SOURCES.txt +0 -0
  21. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication.egg-info/dependency_links.txt +0 -0
  22. {square_authentication-5.1.0 → square_authentication-5.1.2}/square_authentication.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: square_authentication
3
- Version: 5.1.0
3
+ Version: 5.1.2
4
4
  Summary: authentication layer for my personal server.
5
5
  Home-page: https://github.com/thepmsquare/square_authentication
6
6
  Author: thePmSquare
@@ -32,6 +32,16 @@ pip install square_authentication
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v5.1.2
36
+
37
+ - bump square_database_structure>=2.3.1.
38
+ - change logic to read username from profile instead of credentials table.
39
+
40
+ ### v5.1.1
41
+
42
+ - add logger decorator in all functions.
43
+ - add error logs in all endpoints.
44
+
35
45
  ### v5.1.0
36
46
 
37
47
  - Core
@@ -122,3 +132,4 @@ pip install square_authentication
122
132
 
123
133
  ## Feedback is appreciated. Thank you!
124
134
 
135
+
@@ -16,6 +16,16 @@ pip install square_authentication
16
16
 
17
17
  ## changelog
18
18
 
19
+ ### v5.1.2
20
+
21
+ - bump square_database_structure>=2.3.1.
22
+ - change logic to read username from profile instead of credentials table.
23
+
24
+ ### v5.1.1
25
+
26
+ - add logger decorator in all functions.
27
+ - add error logs in all endpoints.
28
+
19
29
  ### v5.1.0
20
30
 
21
31
  - Core
@@ -104,4 +114,4 @@ pip install square_authentication
104
114
 
105
115
  - initial implementation.
106
116
 
107
- ## Feedback is appreciated. Thank you!
117
+ ## Feedback is appreciated. Thank you!
@@ -4,7 +4,7 @@ package_name = "square_authentication"
4
4
 
5
5
  setup(
6
6
  name=package_name,
7
- version="5.1.0",
7
+ version="5.1.2",
8
8
  packages=find_packages(),
9
9
  package_data={
10
10
  package_name: ["data/*"],
@@ -20,7 +20,7 @@ setup(
20
20
  "square_commons>=1.0.0",
21
21
  "square_logger>=1.0.0",
22
22
  "square_database_helper>=2.0.0",
23
- "square_database_structure>=1.0.0",
23
+ "square_database_structure>=2.3.1",
24
24
  "pytest>=8.0.0",
25
25
  "httpx>=0.27.2",
26
26
  ],
@@ -3,23 +3,21 @@ from typing import Annotated, List
3
3
 
4
4
  import bcrypt
5
5
  import jwt
6
- from fastapi import APIRouter, status, Header, HTTPException
6
+ from fastapi import APIRouter, Header, HTTPException, status
7
7
  from fastapi.params import Query
8
8
  from fastapi.responses import JSONResponse
9
9
  from requests import HTTPError
10
10
  from square_commons import get_api_output_in_standard_format
11
11
  from square_database_helper.main import SquareDatabaseHelper
12
- from square_database_helper.pydantic_models import (
13
- FiltersV0,
14
- FilterConditionsV0,
15
- )
12
+ from square_database_helper.pydantic_models import FilterConditionsV0, FiltersV0
16
13
  from square_database_structure.square import global_string_database_name
17
14
  from square_database_structure.square.authentication import global_string_schema_name
18
15
  from square_database_structure.square.authentication.tables import (
19
16
  User,
17
+ UserApp,
20
18
  UserCredential,
21
19
  UserSession,
22
- UserApp,
20
+ UserProfile,
23
21
  )
24
22
  from square_database_structure.square.public import (
25
23
  global_string_schema_name as global_string_public_schema_name,
@@ -27,23 +25,23 @@ from square_database_structure.square.public import (
27
25
  from square_database_structure.square.public.tables import App
28
26
 
29
27
  from square_authentication.configuration import (
30
- global_object_square_logger,
31
- config_str_secret_key_for_access_token,
32
28
  config_int_access_token_valid_minutes,
33
29
  config_int_refresh_token_valid_minutes,
30
+ config_int_square_database_port,
31
+ config_str_secret_key_for_access_token,
34
32
  config_str_secret_key_for_refresh_token,
35
33
  config_str_square_database_ip,
36
- config_int_square_database_port,
37
34
  config_str_square_database_protocol,
35
+ global_object_square_logger,
38
36
  )
39
37
  from square_authentication.messages import messages
40
38
  from square_authentication.pydantic_models.core import (
41
- RegisterUsernameV0,
42
- LoginUsernameV0,
43
39
  DeleteUserV0,
44
- UpdatePasswordV0,
45
- TokenType,
40
+ LoginUsernameV0,
46
41
  LogoutAppsV0,
42
+ RegisterUsernameV0,
43
+ TokenType,
44
+ UpdatePasswordV0,
47
45
  )
48
46
  from square_authentication.utils.token import get_jwt_payload
49
47
 
@@ -78,22 +76,20 @@ async def register_username_v0(
78
76
  """
79
77
 
80
78
  # validation for username
81
- local_list_response_user_creds = global_object_square_database_helper.get_rows_v0(
82
- database_name=global_string_database_name,
83
- schema_name=global_string_schema_name,
84
- table_name=UserCredential.__tablename__,
85
- filters=FiltersV0(
86
- root={
87
- UserCredential.user_credential_username.name: FilterConditionsV0(
88
- eq=username
89
- )
90
- }
91
- ),
92
- )[
93
- "data"
94
- ][
95
- "main"
96
- ]
79
+ local_list_response_user_creds = (
80
+ global_object_square_database_helper.get_rows_v0(
81
+ database_name=global_string_database_name,
82
+ schema_name=global_string_schema_name,
83
+ table_name=UserProfile.__tablename__,
84
+ filters=FiltersV0(
85
+ root={
86
+ UserProfile.user_profile_username.name: FilterConditionsV0(
87
+ eq=username
88
+ )
89
+ }
90
+ ),
91
+ )["data"]["main"]
92
+ )
97
93
  if len(local_list_response_user_creds) > 0:
98
94
  output_content = get_api_output_in_standard_format(
99
95
  message=messages["USERNAME_ALREADY_EXISTS"],
@@ -127,7 +123,6 @@ async def register_username_v0(
127
123
  data=[
128
124
  {
129
125
  UserCredential.user_id.name: local_str_user_id,
130
- UserCredential.user_credential_username.name: username,
131
126
  UserCredential.user_credential_hashed_password.name: local_str_hashed_password,
132
127
  }
133
128
  ],
@@ -135,6 +130,17 @@ async def register_username_v0(
135
130
  schema_name=global_string_schema_name,
136
131
  table_name=UserCredential.__tablename__,
137
132
  )
133
+ global_object_square_database_helper.insert_rows_v0(
134
+ data=[
135
+ {
136
+ UserProfile.user_id.name: local_str_user_id,
137
+ UserProfile.user_profile_username.name: username,
138
+ }
139
+ ],
140
+ database_name=global_string_database_name,
141
+ schema_name=global_string_schema_name,
142
+ table_name=UserProfile.__tablename__,
143
+ )
138
144
  if app_id is not None:
139
145
  # assign app to user
140
146
  global_object_square_database_helper.insert_rows_v0(
@@ -213,6 +219,7 @@ async def register_username_v0(
213
219
  content=output_content,
214
220
  )
215
221
  except HTTPException as http_exception:
222
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
216
223
  return JSONResponse(
217
224
  status_code=http_exception.status_code, content=http_exception.detail
218
225
  )
@@ -257,9 +264,9 @@ async def get_user_details_v0(
257
264
  output_content = get_api_output_in_standard_format(
258
265
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
259
266
  )
260
- return JSONResponse(
267
+ raise HTTPException(
261
268
  status_code=status.HTTP_400_BAD_REQUEST,
262
- content=output_content,
269
+ detail=output_content,
263
270
  )
264
271
  user_id = local_dict_access_token_payload["user_id"]
265
272
  """
@@ -280,13 +287,13 @@ async def get_user_details_v0(
280
287
  root={UserApp.user_id.name: FilterConditionsV0(eq=user_id)}
281
288
  ),
282
289
  )["data"]["main"]
283
- local_list_response_user_credentials = (
290
+ local_list_response_user_profile = (
284
291
  global_object_square_database_helper.get_rows_v0(
285
292
  database_name=global_string_database_name,
286
293
  schema_name=global_string_schema_name,
287
- table_name=UserCredential.__tablename__,
294
+ table_name=UserProfile.__tablename__,
288
295
  filters=FiltersV0(
289
- root={UserCredential.user_id.name: FilterConditionsV0(eq=user_id)}
296
+ root={UserProfile.user_id.name: FilterConditionsV0(eq=user_id)}
290
297
  ),
291
298
  )["data"]["main"]
292
299
  )
@@ -311,8 +318,8 @@ async def get_user_details_v0(
311
318
  return_this = {
312
319
  "user_id": user_id,
313
320
  "credentials": {
314
- "username": local_list_response_user_credentials[0][
315
- UserCredential.user_credential_username.name
321
+ "username": local_list_response_user_profile[0][
322
+ UserProfile.user_profile_username.name
316
323
  ],
317
324
  },
318
325
  "apps": [
@@ -348,6 +355,7 @@ async def get_user_details_v0(
348
355
  content=output_content,
349
356
  )
350
357
  except HTTPException as http_exception:
358
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
351
359
  return JSONResponse(
352
360
  status_code=http_exception.status_code, content=http_exception.detail
353
361
  )
@@ -387,9 +395,9 @@ async def update_user_app_ids_v0(
387
395
  output_content = get_api_output_in_standard_format(
388
396
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
389
397
  )
390
- return JSONResponse(
398
+ raise HTTPException(
391
399
  status_code=status.HTTP_400_BAD_REQUEST,
392
- content=output_content,
400
+ detail=output_content,
393
401
  )
394
402
  user_id = local_dict_access_token_payload["user_id"]
395
403
 
@@ -508,6 +516,7 @@ async def update_user_app_ids_v0(
508
516
  content=output_content,
509
517
  )
510
518
  except HTTPException as http_exception:
519
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
511
520
  return JSONResponse(
512
521
  status_code=http_exception.status_code, content=http_exception.detail
513
522
  )
@@ -539,29 +548,28 @@ async def login_username_v0(body: LoginUsernameV0):
539
548
  validation
540
549
  """
541
550
  # validation for username
542
- local_list_authentication_user_response = global_object_square_database_helper.get_rows_v0(
543
- database_name=global_string_database_name,
544
- schema_name=global_string_schema_name,
545
- table_name=UserCredential.__tablename__,
546
- filters=FiltersV0(
547
- root={
548
- UserCredential.user_credential_username.name: FilterConditionsV0(
549
- eq=username
550
- )
551
- }
552
- ),
553
- )[
554
- "data"
555
- ][
556
- "main"
557
- ]
551
+ local_list_authentication_user_response = (
552
+ global_object_square_database_helper.get_rows_v0(
553
+ database_name=global_string_database_name,
554
+ schema_name=global_string_schema_name,
555
+ table_name=UserProfile.__tablename__,
556
+ filters=FiltersV0(
557
+ root={
558
+ UserProfile.user_profile_username.name: FilterConditionsV0(
559
+ eq=username
560
+ )
561
+ }
562
+ ),
563
+ )["data"]["main"]
564
+ )
558
565
  if len(local_list_authentication_user_response) != 1:
559
566
  output_content = get_api_output_in_standard_format(
560
567
  message=messages["INCORRECT_USERNAME"],
561
568
  log=f"incorrect username {username}",
562
569
  )
563
- return JSONResponse(
564
- status_code=status.HTTP_400_BAD_REQUEST, content=output_content
570
+ raise HTTPException(
571
+ status_code=status.HTTP_400_BAD_REQUEST,
572
+ detail=output_content,
565
573
  )
566
574
  # validate if app_id is assigned to user
567
575
  # this will also validate if app_id is valid
@@ -597,16 +605,17 @@ async def login_username_v0(body: LoginUsernameV0):
597
605
  message=messages["GENERIC_400"],
598
606
  log=str(he),
599
607
  )
600
- return JSONResponse(
601
- status_code=he.response.status_code, content=output_content
608
+ raise HTTPException(
609
+ status_code=he.response.status_code, detail=output_content
602
610
  )
603
611
  else:
604
612
  output_content = get_api_output_in_standard_format(
605
613
  message=messages["GENERIC_400"],
606
614
  log=f"user_id {local_str_user_id}({username}) not assigned to app {app_id}.",
607
615
  )
608
- return JSONResponse(
609
- status_code=status.HTTP_400_BAD_REQUEST, content=output_content
616
+ raise HTTPException(
617
+ status_code=status.HTTP_400_BAD_REQUEST,
618
+ detail=output_content,
610
619
  )
611
620
 
612
621
  # validate password
@@ -622,9 +631,9 @@ async def login_username_v0(body: LoginUsernameV0):
622
631
  message=messages["INCORRECT_PASSWORD"],
623
632
  log=f"incorrect password for user_id {local_str_user_id}({username}).",
624
633
  )
625
- return JSONResponse(
634
+ raise HTTPException(
626
635
  status_code=status.HTTP_400_BAD_REQUEST,
627
- content=output_content,
636
+ detail=output_content,
628
637
  )
629
638
  """
630
639
  main process
@@ -692,6 +701,7 @@ async def login_username_v0(body: LoginUsernameV0):
692
701
  content=output_content,
693
702
  )
694
703
  except HTTPException as http_exception:
704
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
695
705
  return JSONResponse(
696
706
  status_code=http_exception.status_code, content=http_exception.detail
697
707
  )
@@ -740,9 +750,9 @@ async def generate_access_token_v0(
740
750
  message=messages["INCORRECT_REFRESH_TOKEN"],
741
751
  log=f"incorrect refresh token: {refresh_token}.",
742
752
  )
743
- return JSONResponse(
753
+ raise HTTPException(
744
754
  status_code=status.HTTP_400_BAD_REQUEST,
745
- content=output_content,
755
+ detail=output_content,
746
756
  )
747
757
  # validating if the refresh token is valid, active and of the same user.
748
758
  try:
@@ -753,9 +763,9 @@ async def generate_access_token_v0(
753
763
  output_content = get_api_output_in_standard_format(
754
764
  message=messages["INCORRECT_REFRESH_TOKEN"], log=str(error)
755
765
  )
756
- return JSONResponse(
766
+ raise HTTPException(
757
767
  status_code=status.HTTP_400_BAD_REQUEST,
758
- content=output_content,
768
+ detail=output_content,
759
769
  )
760
770
  """
761
771
  main process
@@ -782,6 +792,7 @@ async def generate_access_token_v0(
782
792
  content=output_content,
783
793
  )
784
794
  except HTTPException as http_exception:
795
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
785
796
  return JSONResponse(
786
797
  status_code=http_exception.status_code, content=http_exception.detail
787
798
  )
@@ -830,23 +841,21 @@ async def logout_v0(
830
841
  message=messages["INCORRECT_REFRESH_TOKEN"],
831
842
  log=f"incorrect refresh token: {refresh_token}.",
832
843
  )
833
- return JSONResponse(
844
+ raise HTTPException(
834
845
  status_code=status.HTTP_400_BAD_REQUEST,
835
- content=output_content,
846
+ detail=output_content,
836
847
  )
837
848
  # validating if the refresh token is valid, active and of the same user.
838
849
  try:
839
- local_dict_refresh_token_payload = get_jwt_payload(
840
- refresh_token, config_str_secret_key_for_refresh_token
841
- )
850
+ _ = get_jwt_payload(refresh_token, config_str_secret_key_for_refresh_token)
842
851
  except Exception as error:
843
852
  output_content = get_api_output_in_standard_format(
844
853
  message=messages["INCORRECT_REFRESH_TOKEN"],
845
854
  log=str(error),
846
855
  )
847
- return JSONResponse(
856
+ raise HTTPException(
848
857
  status_code=status.HTTP_400_BAD_REQUEST,
849
- content=output_content,
858
+ detail=output_content,
850
859
  )
851
860
  # ======================================================================================
852
861
  # NOTE: if refresh token has expired no need to delete it during this call
@@ -875,6 +884,7 @@ async def logout_v0(
875
884
  )
876
885
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
877
886
  except HTTPException as http_exception:
887
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
878
888
  return JSONResponse(
879
889
  status_code=http_exception.status_code, content=http_exception.detail
880
890
  )
@@ -911,9 +921,9 @@ async def logout_apps_v0(
911
921
  output_content = get_api_output_in_standard_format(
912
922
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
913
923
  )
914
- return JSONResponse(
924
+ raise HTTPException(
915
925
  status_code=status.HTTP_400_BAD_REQUEST,
916
- content=output_content,
926
+ detail=output_content,
917
927
  )
918
928
  user_id = local_dict_access_token_payload["user_id"]
919
929
  # validate app_ids
@@ -967,6 +977,7 @@ async def logout_apps_v0(
967
977
  )
968
978
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
969
979
  except HTTPException as http_exception:
980
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
970
981
  return JSONResponse(
971
982
  status_code=http_exception.status_code, content=http_exception.detail
972
983
  )
@@ -1002,9 +1013,9 @@ async def logout_all_v0(
1002
1013
  output_content = get_api_output_in_standard_format(
1003
1014
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
1004
1015
  )
1005
- return JSONResponse(
1016
+ raise HTTPException(
1006
1017
  status_code=status.HTTP_400_BAD_REQUEST,
1007
- content=output_content,
1018
+ detail=output_content,
1008
1019
  )
1009
1020
  user_id = local_dict_access_token_payload["user_id"]
1010
1021
 
@@ -1030,6 +1041,7 @@ async def logout_all_v0(
1030
1041
  )
1031
1042
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
1032
1043
  except HTTPException as http_exception:
1044
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
1033
1045
  return JSONResponse(
1034
1046
  status_code=http_exception.status_code, content=http_exception.detail
1035
1047
  )
@@ -1066,9 +1078,9 @@ async def update_username_v0(
1066
1078
  output_content = get_api_output_in_standard_format(
1067
1079
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
1068
1080
  )
1069
- return JSONResponse(
1081
+ raise HTTPException(
1070
1082
  status_code=status.HTTP_400_BAD_REQUEST,
1071
- content=output_content,
1083
+ detail=output_content,
1072
1084
  )
1073
1085
  user_id = local_dict_access_token_payload["user_id"]
1074
1086
 
@@ -1089,36 +1101,34 @@ async def update_username_v0(
1089
1101
  message=messages["INCORRECT_USER_ID"],
1090
1102
  log=f"incorrect user_id: {user_id}.",
1091
1103
  )
1092
- return JSONResponse(
1104
+ raise HTTPException(
1093
1105
  status_code=status.HTTP_400_BAD_REQUEST,
1094
- content=output_content,
1106
+ detail=output_content,
1095
1107
  )
1096
1108
 
1097
1109
  # validate new username
1098
- local_list_user_credentials_response = global_object_square_database_helper.get_rows_v0(
1099
- database_name=global_string_database_name,
1100
- schema_name=global_string_schema_name,
1101
- table_name=UserCredential.__tablename__,
1102
- filters=FiltersV0(
1103
- root={
1104
- UserCredential.user_credential_username.name: FilterConditionsV0(
1105
- eq=new_username
1106
- ),
1107
- }
1108
- ),
1109
- )[
1110
- "data"
1111
- ][
1112
- "main"
1113
- ]
1110
+ local_list_user_credentials_response = (
1111
+ global_object_square_database_helper.get_rows_v0(
1112
+ database_name=global_string_database_name,
1113
+ schema_name=global_string_schema_name,
1114
+ table_name=UserProfile.__tablename__,
1115
+ filters=FiltersV0(
1116
+ root={
1117
+ UserProfile.user_profile_username.name: FilterConditionsV0(
1118
+ eq=new_username
1119
+ ),
1120
+ }
1121
+ ),
1122
+ )["data"]["main"]
1123
+ )
1114
1124
  if len(local_list_user_credentials_response) != 0:
1115
1125
  output_content = get_api_output_in_standard_format(
1116
1126
  message=messages["USERNAME_ALREADY_EXISTS"],
1117
1127
  log=f"{new_username} is taken.",
1118
1128
  )
1119
- return JSONResponse(
1120
- status_code=status.HTTP_409_CONFLICT,
1121
- content=output_content,
1129
+ raise HTTPException(
1130
+ status_code=status.HTTP_400_BAD_REQUEST,
1131
+ detail=output_content,
1122
1132
  )
1123
1133
  """
1124
1134
  main process
@@ -1127,14 +1137,14 @@ async def update_username_v0(
1127
1137
  global_object_square_database_helper.edit_rows_v0(
1128
1138
  database_name=global_string_database_name,
1129
1139
  schema_name=global_string_schema_name,
1130
- table_name=UserCredential.__tablename__,
1140
+ table_name=UserProfile.__tablename__,
1131
1141
  filters=FiltersV0(
1132
1142
  root={
1133
- UserCredential.user_id.name: FilterConditionsV0(eq=user_id),
1143
+ UserProfile.user_id.name: FilterConditionsV0(eq=user_id),
1134
1144
  }
1135
1145
  ),
1136
1146
  data={
1137
- UserCredential.user_credential_username.name: new_username,
1147
+ UserProfile.user_profile_username.name: new_username,
1138
1148
  },
1139
1149
  )
1140
1150
  """
@@ -1146,6 +1156,7 @@ async def update_username_v0(
1146
1156
  )
1147
1157
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
1148
1158
  except HTTPException as http_exception:
1159
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
1149
1160
  return JSONResponse(
1150
1161
  status_code=http_exception.status_code, content=http_exception.detail
1151
1162
  )
@@ -1183,9 +1194,9 @@ async def delete_user_v0(
1183
1194
  output_content = get_api_output_in_standard_format(
1184
1195
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
1185
1196
  )
1186
- return JSONResponse(
1197
+ raise HTTPException(
1187
1198
  status_code=status.HTTP_400_BAD_REQUEST,
1188
- content=output_content,
1199
+ detail=output_content,
1189
1200
  )
1190
1201
  user_id = local_dict_access_token_payload["user_id"]
1191
1202
 
@@ -1205,8 +1216,9 @@ async def delete_user_v0(
1205
1216
  message=messages["INCORRECT_USER_ID"],
1206
1217
  log=f"incorrect user_id: {user_id}.",
1207
1218
  )
1208
- return JSONResponse(
1209
- status_code=status.HTTP_400_BAD_REQUEST, content=output_content
1219
+ raise HTTPException(
1220
+ status_code=status.HTTP_400_BAD_REQUEST,
1221
+ detail=output_content,
1210
1222
  )
1211
1223
 
1212
1224
  # validate password
@@ -1223,9 +1235,9 @@ async def delete_user_v0(
1223
1235
  message=messages["INCORRECT_PASSWORD"],
1224
1236
  log=f"incorrect password for user_id {user_id}.",
1225
1237
  )
1226
- return JSONResponse(
1238
+ raise HTTPException(
1227
1239
  status_code=status.HTTP_400_BAD_REQUEST,
1228
- content=output_content,
1240
+ detail=output_content,
1229
1241
  )
1230
1242
  """
1231
1243
  main process
@@ -1250,6 +1262,7 @@ async def delete_user_v0(
1250
1262
  )
1251
1263
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
1252
1264
  except HTTPException as http_exception:
1265
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
1253
1266
  return JSONResponse(
1254
1267
  status_code=http_exception.status_code, content=http_exception.detail
1255
1268
  )
@@ -1288,9 +1301,9 @@ async def update_password_v0(
1288
1301
  output_content = get_api_output_in_standard_format(
1289
1302
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
1290
1303
  )
1291
- return JSONResponse(
1304
+ raise HTTPException(
1292
1305
  status_code=status.HTTP_400_BAD_REQUEST,
1293
- content=output_content,
1306
+ detail=output_content,
1294
1307
  )
1295
1308
  user_id = local_dict_access_token_payload["user_id"]
1296
1309
 
@@ -1310,8 +1323,9 @@ async def update_password_v0(
1310
1323
  message=messages["INCORRECT_USER_ID"],
1311
1324
  log=f"incorrect user_id: {user_id}.",
1312
1325
  )
1313
- return JSONResponse(
1314
- status_code=status.HTTP_400_BAD_REQUEST, content=output_content
1326
+ raise HTTPException(
1327
+ status_code=status.HTTP_400_BAD_REQUEST,
1328
+ detail=output_content,
1315
1329
  )
1316
1330
 
1317
1331
  # validate password
@@ -1328,9 +1342,9 @@ async def update_password_v0(
1328
1342
  message=messages["INCORRECT_PASSWORD"],
1329
1343
  log=f"incorrect password for user_id {user_id}.",
1330
1344
  )
1331
- return JSONResponse(
1345
+ raise HTTPException(
1332
1346
  status_code=status.HTTP_400_BAD_REQUEST,
1333
- content=output_content,
1347
+ detail=output_content,
1334
1348
  )
1335
1349
  """
1336
1350
  main process
@@ -1361,6 +1375,7 @@ async def update_password_v0(
1361
1375
  )
1362
1376
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
1363
1377
  except HTTPException as http_exception:
1378
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
1364
1379
  return JSONResponse(
1365
1380
  status_code=http_exception.status_code, content=http_exception.detail
1366
1381
  )
@@ -1424,11 +1439,12 @@ async def validate_and_get_payload_from_token_v0(
1424
1439
  message=messages["INCORRECT_REFRESH_TOKEN"],
1425
1440
  log="refresh token valid but not present in database.",
1426
1441
  )
1427
- return JSONResponse(
1442
+ raise HTTPException(
1428
1443
  status_code=status.HTTP_400_BAD_REQUEST,
1429
- content=output_content,
1444
+ detail=output_content,
1430
1445
  )
1431
-
1446
+ except HTTPException as http_exception:
1447
+ raise
1432
1448
  except Exception as error:
1433
1449
  output_content = None
1434
1450
  if token_type == TokenType.access_token:
@@ -1440,9 +1456,9 @@ async def validate_and_get_payload_from_token_v0(
1440
1456
  message=messages["INCORRECT_REFRESH_TOKEN"], log=str(error)
1441
1457
  )
1442
1458
 
1443
- return JSONResponse(
1459
+ raise HTTPException(
1444
1460
  status_code=status.HTTP_400_BAD_REQUEST,
1445
- content=output_content,
1461
+ detail=output_content,
1446
1462
  )
1447
1463
 
1448
1464
  """
@@ -1458,6 +1474,7 @@ async def validate_and_get_payload_from_token_v0(
1458
1474
  )
1459
1475
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
1460
1476
  except HTTPException as http_exception:
1477
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
1461
1478
  return JSONResponse(
1462
1479
  status_code=http_exception.status_code, content=http_exception.detail
1463
1480
  )
@@ -4,7 +4,10 @@ from cryptography.hazmat.backends import default_backend
4
4
  from cryptography.hazmat.primitives import padding
5
5
  from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
6
6
 
7
+ from square_authentication.configuration import global_object_square_logger
7
8
 
9
+
10
+ @global_object_square_logger.auto_logger
8
11
  def encrypt(key, plaintext):
9
12
  # Ensure the key length is 16, 24, or 32 bytes for AES
10
13
  key = key.ljust(32)[:32].encode('utf-8')
@@ -28,7 +31,7 @@ def encrypt(key, plaintext):
28
31
 
29
32
  return encoded_ciphertext
30
33
 
31
-
34
+ @global_object_square_logger.auto_logger
32
35
  def decrypt(key, encoded_ciphertext):
33
36
  # Ensure the key length is 16, 24, or 32 bytes for AES
34
37
  key = key.ljust(32)[:32].encode('utf-8')
@@ -1,7 +1,10 @@
1
1
  import jwt
2
2
  from jwt.exceptions import ExpiredSignatureError, DecodeError, InvalidTokenError
3
3
 
4
+ from square_authentication.configuration import global_object_square_logger
4
5
 
6
+
7
+ @global_object_square_logger.auto_logger
5
8
  def get_jwt_payload(token, secret_key):
6
9
  try:
7
10
  # Decode the token and verify the signature
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: square-authentication
3
- Version: 5.1.0
3
+ Version: 5.1.2
4
4
  Summary: authentication layer for my personal server.
5
5
  Home-page: https://github.com/thepmsquare/square_authentication
6
6
  Author: thePmSquare
@@ -32,6 +32,16 @@ pip install square_authentication
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v5.1.2
36
+
37
+ - bump square_database_structure>=2.3.1.
38
+ - change logic to read username from profile instead of credentials table.
39
+
40
+ ### v5.1.1
41
+
42
+ - add logger decorator in all functions.
43
+ - add error logs in all endpoints.
44
+
35
45
  ### v5.1.0
36
46
 
37
47
  - Core
@@ -122,3 +132,4 @@ pip install square_authentication
122
132
 
123
133
  ## Feedback is appreciated. Thank you!
124
134
 
135
+
@@ -8,6 +8,6 @@ cryptography>=42.0.7
8
8
  square_commons>=1.0.0
9
9
  square_logger>=1.0.0
10
10
  square_database_helper>=2.0.0
11
- square_database_structure>=1.0.0
11
+ square_database_structure>=2.3.1
12
12
  pytest>=8.0.0
13
13
  httpx>=0.27.2