square-authentication 5.0.1__tar.gz → 5.1.1__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.0.1 → square_authentication-5.1.1}/PKG-INFO +13 -1
  2. {square_authentication-5.0.1 → square_authentication-5.1.1}/README.md +12 -1
  3. {square_authentication-5.0.1 → square_authentication-5.1.1}/setup.py +1 -1
  4. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/pydantic_models/core.py +5 -1
  5. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/routes/core.py +226 -56
  6. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/utils/encryption.py +4 -1
  7. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/utils/token.py +3 -0
  8. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication.egg-info/PKG-INFO +13 -1
  9. {square_authentication-5.0.1 → square_authentication-5.1.1}/setup.cfg +0 -0
  10. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/__init__.py +0 -0
  11. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/configuration.py +0 -0
  12. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/data/config.ini +0 -0
  13. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/main.py +0 -0
  14. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/messages.py +0 -0
  15. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/pydantic_models/__init__.py +0 -0
  16. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/routes/__init__.py +0 -0
  17. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/routes/utility.py +0 -0
  18. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication/utils/__init__.py +0 -0
  19. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication.egg-info/SOURCES.txt +0 -0
  20. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication.egg-info/dependency_links.txt +0 -0
  21. {square_authentication-5.0.1 → square_authentication-5.1.1}/square_authentication.egg-info/requires.txt +0 -0
  22. {square_authentication-5.0.1 → square_authentication-5.1.1}/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.0.1
3
+ Version: 5.1.1
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,17 @@ pip install square_authentication
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v5.1.1
36
+
37
+ - add logger decorator in all functions.
38
+ - add error logs in all endpoints.
39
+
40
+ ### v5.1.0
41
+
42
+ - Core
43
+ - add logout/apps/v0.
44
+ - add logout/all/v0.
45
+
35
46
  ### v5.0.1
36
47
 
37
48
  - fix typo in return value of get_user_details_v0.
@@ -116,3 +127,4 @@ pip install square_authentication
116
127
 
117
128
  ## Feedback is appreciated. Thank you!
118
129
 
130
+
@@ -16,6 +16,17 @@ pip install square_authentication
16
16
 
17
17
  ## changelog
18
18
 
19
+ ### v5.1.1
20
+
21
+ - add logger decorator in all functions.
22
+ - add error logs in all endpoints.
23
+
24
+ ### v5.1.0
25
+
26
+ - Core
27
+ - add logout/apps/v0.
28
+ - add logout/all/v0.
29
+
19
30
  ### v5.0.1
20
31
 
21
32
  - fix typo in return value of get_user_details_v0.
@@ -98,4 +109,4 @@ pip install square_authentication
98
109
 
99
110
  - initial implementation.
100
111
 
101
- ## Feedback is appreciated. Thank you!
112
+ ## 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.0.1",
7
+ version="5.1.1",
8
8
  packages=find_packages(),
9
9
  package_data={
10
10
  package_name: ["data/*"],
@@ -1,5 +1,5 @@
1
1
  from enum import Enum
2
- from typing import Optional
2
+ from typing import Optional, List
3
3
 
4
4
  from pydantic import BaseModel
5
5
 
@@ -29,3 +29,7 @@ class UpdatePasswordV0(BaseModel):
29
29
  class TokenType(Enum):
30
30
  access_token = "access_token"
31
31
  refresh_token = "refresh_token"
32
+
33
+
34
+ class LogoutAppsV0(BaseModel):
35
+ app_ids: List[int]
@@ -3,23 +3,20 @@ 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,
23
20
  )
24
21
  from square_database_structure.square.public import (
25
22
  global_string_schema_name as global_string_public_schema_name,
@@ -27,22 +24,23 @@ from square_database_structure.square.public import (
27
24
  from square_database_structure.square.public.tables import App
28
25
 
29
26
  from square_authentication.configuration import (
30
- global_object_square_logger,
31
- config_str_secret_key_for_access_token,
32
27
  config_int_access_token_valid_minutes,
33
28
  config_int_refresh_token_valid_minutes,
29
+ config_int_square_database_port,
30
+ config_str_secret_key_for_access_token,
34
31
  config_str_secret_key_for_refresh_token,
35
32
  config_str_square_database_ip,
36
- config_int_square_database_port,
37
33
  config_str_square_database_protocol,
34
+ global_object_square_logger,
38
35
  )
39
36
  from square_authentication.messages import messages
40
37
  from square_authentication.pydantic_models.core import (
41
- RegisterUsernameV0,
42
- LoginUsernameV0,
43
38
  DeleteUserV0,
44
- UpdatePasswordV0,
39
+ LoginUsernameV0,
40
+ LogoutAppsV0,
41
+ RegisterUsernameV0,
45
42
  TokenType,
43
+ UpdatePasswordV0,
46
44
  )
47
45
  from square_authentication.utils.token import get_jwt_payload
48
46
 
@@ -212,6 +210,7 @@ async def register_username_v0(
212
210
  content=output_content,
213
211
  )
214
212
  except HTTPException as http_exception:
213
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
215
214
  return JSONResponse(
216
215
  status_code=http_exception.status_code, content=http_exception.detail
217
216
  )
@@ -256,9 +255,9 @@ async def get_user_details_v0(
256
255
  output_content = get_api_output_in_standard_format(
257
256
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
258
257
  )
259
- return JSONResponse(
258
+ raise HTTPException(
260
259
  status_code=status.HTTP_400_BAD_REQUEST,
261
- content=output_content,
260
+ detail=output_content,
262
261
  )
263
262
  user_id = local_dict_access_token_payload["user_id"]
264
263
  """
@@ -347,6 +346,7 @@ async def get_user_details_v0(
347
346
  content=output_content,
348
347
  )
349
348
  except HTTPException as http_exception:
349
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
350
350
  return JSONResponse(
351
351
  status_code=http_exception.status_code, content=http_exception.detail
352
352
  )
@@ -386,9 +386,9 @@ async def update_user_app_ids_v0(
386
386
  output_content = get_api_output_in_standard_format(
387
387
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
388
388
  )
389
- return JSONResponse(
389
+ raise HTTPException(
390
390
  status_code=status.HTTP_400_BAD_REQUEST,
391
- content=output_content,
391
+ detail=output_content,
392
392
  )
393
393
  user_id = local_dict_access_token_payload["user_id"]
394
394
 
@@ -507,6 +507,7 @@ async def update_user_app_ids_v0(
507
507
  content=output_content,
508
508
  )
509
509
  except HTTPException as http_exception:
510
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
510
511
  return JSONResponse(
511
512
  status_code=http_exception.status_code, content=http_exception.detail
512
513
  )
@@ -559,8 +560,9 @@ async def login_username_v0(body: LoginUsernameV0):
559
560
  message=messages["INCORRECT_USERNAME"],
560
561
  log=f"incorrect username {username}",
561
562
  )
562
- return JSONResponse(
563
- status_code=status.HTTP_400_BAD_REQUEST, content=output_content
563
+ raise HTTPException(
564
+ status_code=status.HTTP_400_BAD_REQUEST,
565
+ detail=output_content,
564
566
  )
565
567
  # validate if app_id is assigned to user
566
568
  # this will also validate if app_id is valid
@@ -596,16 +598,17 @@ async def login_username_v0(body: LoginUsernameV0):
596
598
  message=messages["GENERIC_400"],
597
599
  log=str(he),
598
600
  )
599
- return JSONResponse(
600
- status_code=he.response.status_code, content=output_content
601
+ raise HTTPException(
602
+ status_code=he.response.status_code, detail=output_content
601
603
  )
602
604
  else:
603
605
  output_content = get_api_output_in_standard_format(
604
606
  message=messages["GENERIC_400"],
605
607
  log=f"user_id {local_str_user_id}({username}) not assigned to app {app_id}.",
606
608
  )
607
- return JSONResponse(
608
- status_code=status.HTTP_400_BAD_REQUEST, content=output_content
609
+ raise HTTPException(
610
+ status_code=status.HTTP_400_BAD_REQUEST,
611
+ detail=output_content,
609
612
  )
610
613
 
611
614
  # validate password
@@ -621,9 +624,9 @@ async def login_username_v0(body: LoginUsernameV0):
621
624
  message=messages["INCORRECT_PASSWORD"],
622
625
  log=f"incorrect password for user_id {local_str_user_id}({username}).",
623
626
  )
624
- return JSONResponse(
627
+ raise HTTPException(
625
628
  status_code=status.HTTP_400_BAD_REQUEST,
626
- content=output_content,
629
+ detail=output_content,
627
630
  )
628
631
  """
629
632
  main process
@@ -691,6 +694,7 @@ async def login_username_v0(body: LoginUsernameV0):
691
694
  content=output_content,
692
695
  )
693
696
  except HTTPException as http_exception:
697
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
694
698
  return JSONResponse(
695
699
  status_code=http_exception.status_code, content=http_exception.detail
696
700
  )
@@ -739,9 +743,9 @@ async def generate_access_token_v0(
739
743
  message=messages["INCORRECT_REFRESH_TOKEN"],
740
744
  log=f"incorrect refresh token: {refresh_token}.",
741
745
  )
742
- return JSONResponse(
746
+ raise HTTPException(
743
747
  status_code=status.HTTP_400_BAD_REQUEST,
744
- content=output_content,
748
+ detail=output_content,
745
749
  )
746
750
  # validating if the refresh token is valid, active and of the same user.
747
751
  try:
@@ -752,9 +756,9 @@ async def generate_access_token_v0(
752
756
  output_content = get_api_output_in_standard_format(
753
757
  message=messages["INCORRECT_REFRESH_TOKEN"], log=str(error)
754
758
  )
755
- return JSONResponse(
759
+ raise HTTPException(
756
760
  status_code=status.HTTP_400_BAD_REQUEST,
757
- content=output_content,
761
+ detail=output_content,
758
762
  )
759
763
  """
760
764
  main process
@@ -781,6 +785,7 @@ async def generate_access_token_v0(
781
785
  content=output_content,
782
786
  )
783
787
  except HTTPException as http_exception:
788
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
784
789
  return JSONResponse(
785
790
  status_code=http_exception.status_code, content=http_exception.detail
786
791
  )
@@ -829,9 +834,9 @@ async def logout_v0(
829
834
  message=messages["INCORRECT_REFRESH_TOKEN"],
830
835
  log=f"incorrect refresh token: {refresh_token}.",
831
836
  )
832
- return JSONResponse(
837
+ raise HTTPException(
833
838
  status_code=status.HTTP_400_BAD_REQUEST,
834
- content=output_content,
839
+ detail=output_content,
835
840
  )
836
841
  # validating if the refresh token is valid, active and of the same user.
837
842
  try:
@@ -843,9 +848,9 @@ async def logout_v0(
843
848
  message=messages["INCORRECT_REFRESH_TOKEN"],
844
849
  log=str(error),
845
850
  )
846
- return JSONResponse(
851
+ raise HTTPException(
847
852
  status_code=status.HTTP_400_BAD_REQUEST,
848
- content=output_content,
853
+ detail=output_content,
849
854
  )
850
855
  # ======================================================================================
851
856
  # NOTE: if refresh token has expired no need to delete it during this call
@@ -874,6 +879,164 @@ async def logout_v0(
874
879
  )
875
880
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
876
881
  except HTTPException as http_exception:
882
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
883
+ return JSONResponse(
884
+ status_code=http_exception.status_code, content=http_exception.detail
885
+ )
886
+ except Exception as e:
887
+ """
888
+ rollback logic
889
+ """
890
+ global_object_square_logger.logger.error(e, exc_info=True)
891
+ output_content = get_api_output_in_standard_format(
892
+ message=messages["GENERIC_500"],
893
+ log=str(e),
894
+ )
895
+ return JSONResponse(
896
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
897
+ )
898
+
899
+
900
+ @router.delete("/logout/apps/v0")
901
+ @global_object_square_logger.async_auto_logger
902
+ async def logout_apps_v0(
903
+ access_token: Annotated[str, Header()],
904
+ body: LogoutAppsV0,
905
+ ):
906
+ app_ids = body.app_ids
907
+ try:
908
+ """
909
+ validation
910
+ """
911
+ try:
912
+ local_dict_access_token_payload = get_jwt_payload(
913
+ access_token, config_str_secret_key_for_access_token
914
+ )
915
+ except Exception as error:
916
+ output_content = get_api_output_in_standard_format(
917
+ message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
918
+ )
919
+ raise HTTPException(
920
+ status_code=status.HTTP_400_BAD_REQUEST,
921
+ detail=output_content,
922
+ )
923
+ user_id = local_dict_access_token_payload["user_id"]
924
+ # validate app_ids
925
+ app_ids = list(set(app_ids))
926
+ local_list_response_user_app = global_object_square_database_helper.get_rows_v0(
927
+ database_name=global_string_database_name,
928
+ schema_name=global_string_schema_name,
929
+ table_name=UserApp.__tablename__,
930
+ filters=FiltersV0(
931
+ root={
932
+ UserApp.user_id.name: FilterConditionsV0(eq=user_id),
933
+ }
934
+ ),
935
+ columns=[UserApp.app_id.name],
936
+ )["data"]["main"]
937
+ local_list_user_app_ids = [
938
+ x[UserApp.app_id.name] for x in local_list_response_user_app
939
+ ]
940
+ local_list_invalid_app_ids = [
941
+ x for x in app_ids if x not in local_list_user_app_ids
942
+ ]
943
+ if len(local_list_invalid_app_ids) > 0:
944
+ output_content = get_api_output_in_standard_format(
945
+ message=messages["GENERIC_400"],
946
+ log=f"invalid app_ids: {local_list_invalid_app_ids}.",
947
+ )
948
+ raise HTTPException(
949
+ status_code=status.HTTP_400_BAD_REQUEST,
950
+ detail=output_content,
951
+ )
952
+ """
953
+ main process
954
+ """
955
+ # delete session for user
956
+ global_object_square_database_helper.delete_rows_v0(
957
+ database_name=global_string_database_name,
958
+ schema_name=global_string_schema_name,
959
+ table_name=UserSession.__tablename__,
960
+ filters=FiltersV0(
961
+ root={
962
+ UserSession.user_id.name: FilterConditionsV0(eq=user_id),
963
+ UserSession.app_id.name: FilterConditionsV0(in_=app_ids),
964
+ }
965
+ ),
966
+ )
967
+ """
968
+ return value
969
+ """
970
+ output_content = get_api_output_in_standard_format(
971
+ message=messages["LOGOUT_SUCCESSFUL"],
972
+ )
973
+ return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
974
+ except HTTPException as http_exception:
975
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
976
+ return JSONResponse(
977
+ status_code=http_exception.status_code, content=http_exception.detail
978
+ )
979
+ except Exception as e:
980
+ """
981
+ rollback logic
982
+ """
983
+ global_object_square_logger.logger.error(e, exc_info=True)
984
+ output_content = get_api_output_in_standard_format(
985
+ message=messages["GENERIC_500"],
986
+ log=str(e),
987
+ )
988
+ return JSONResponse(
989
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
990
+ )
991
+
992
+
993
+ @router.delete("/logout/all/v0")
994
+ @global_object_square_logger.async_auto_logger
995
+ async def logout_all_v0(
996
+ access_token: Annotated[str, Header()],
997
+ ):
998
+
999
+ try:
1000
+ """
1001
+ validation
1002
+ """
1003
+ try:
1004
+ local_dict_access_token_payload = get_jwt_payload(
1005
+ access_token, config_str_secret_key_for_access_token
1006
+ )
1007
+ except Exception as error:
1008
+ output_content = get_api_output_in_standard_format(
1009
+ message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
1010
+ )
1011
+ raise HTTPException(
1012
+ status_code=status.HTTP_400_BAD_REQUEST,
1013
+ detail=output_content,
1014
+ )
1015
+ user_id = local_dict_access_token_payload["user_id"]
1016
+
1017
+ """
1018
+ main process
1019
+ """
1020
+ # delete session for user
1021
+ global_object_square_database_helper.delete_rows_v0(
1022
+ database_name=global_string_database_name,
1023
+ schema_name=global_string_schema_name,
1024
+ table_name=UserSession.__tablename__,
1025
+ filters=FiltersV0(
1026
+ root={
1027
+ UserSession.user_id.name: FilterConditionsV0(eq=user_id),
1028
+ }
1029
+ ),
1030
+ )
1031
+ """
1032
+ return value
1033
+ """
1034
+ output_content = get_api_output_in_standard_format(
1035
+ message=messages["LOGOUT_SUCCESSFUL"],
1036
+ )
1037
+ return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
1038
+ except HTTPException as http_exception:
1039
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
877
1040
  return JSONResponse(
878
1041
  status_code=http_exception.status_code, content=http_exception.detail
879
1042
  )
@@ -910,9 +1073,9 @@ async def update_username_v0(
910
1073
  output_content = get_api_output_in_standard_format(
911
1074
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
912
1075
  )
913
- return JSONResponse(
1076
+ raise HTTPException(
914
1077
  status_code=status.HTTP_400_BAD_REQUEST,
915
- content=output_content,
1078
+ detail=output_content,
916
1079
  )
917
1080
  user_id = local_dict_access_token_payload["user_id"]
918
1081
 
@@ -933,9 +1096,9 @@ async def update_username_v0(
933
1096
  message=messages["INCORRECT_USER_ID"],
934
1097
  log=f"incorrect user_id: {user_id}.",
935
1098
  )
936
- return JSONResponse(
1099
+ raise HTTPException(
937
1100
  status_code=status.HTTP_400_BAD_REQUEST,
938
- content=output_content,
1101
+ detail=output_content,
939
1102
  )
940
1103
 
941
1104
  # validate new username
@@ -960,9 +1123,9 @@ async def update_username_v0(
960
1123
  message=messages["USERNAME_ALREADY_EXISTS"],
961
1124
  log=f"{new_username} is taken.",
962
1125
  )
963
- return JSONResponse(
964
- status_code=status.HTTP_409_CONFLICT,
965
- content=output_content,
1126
+ raise HTTPException(
1127
+ status_code=status.HTTP_400_BAD_REQUEST,
1128
+ detail=output_content,
966
1129
  )
967
1130
  """
968
1131
  main process
@@ -990,6 +1153,7 @@ async def update_username_v0(
990
1153
  )
991
1154
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
992
1155
  except HTTPException as http_exception:
1156
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
993
1157
  return JSONResponse(
994
1158
  status_code=http_exception.status_code, content=http_exception.detail
995
1159
  )
@@ -1027,9 +1191,9 @@ async def delete_user_v0(
1027
1191
  output_content = get_api_output_in_standard_format(
1028
1192
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
1029
1193
  )
1030
- return JSONResponse(
1194
+ raise HTTPException(
1031
1195
  status_code=status.HTTP_400_BAD_REQUEST,
1032
- content=output_content,
1196
+ detail=output_content,
1033
1197
  )
1034
1198
  user_id = local_dict_access_token_payload["user_id"]
1035
1199
 
@@ -1049,8 +1213,9 @@ async def delete_user_v0(
1049
1213
  message=messages["INCORRECT_USER_ID"],
1050
1214
  log=f"incorrect user_id: {user_id}.",
1051
1215
  )
1052
- return JSONResponse(
1053
- status_code=status.HTTP_400_BAD_REQUEST, content=output_content
1216
+ raise HTTPException(
1217
+ status_code=status.HTTP_400_BAD_REQUEST,
1218
+ detail=output_content,
1054
1219
  )
1055
1220
 
1056
1221
  # validate password
@@ -1067,9 +1232,9 @@ async def delete_user_v0(
1067
1232
  message=messages["INCORRECT_PASSWORD"],
1068
1233
  log=f"incorrect password for user_id {user_id}.",
1069
1234
  )
1070
- return JSONResponse(
1235
+ raise HTTPException(
1071
1236
  status_code=status.HTTP_400_BAD_REQUEST,
1072
- content=output_content,
1237
+ detail=output_content,
1073
1238
  )
1074
1239
  """
1075
1240
  main process
@@ -1094,6 +1259,7 @@ async def delete_user_v0(
1094
1259
  )
1095
1260
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
1096
1261
  except HTTPException as http_exception:
1262
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
1097
1263
  return JSONResponse(
1098
1264
  status_code=http_exception.status_code, content=http_exception.detail
1099
1265
  )
@@ -1132,9 +1298,9 @@ async def update_password_v0(
1132
1298
  output_content = get_api_output_in_standard_format(
1133
1299
  message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
1134
1300
  )
1135
- return JSONResponse(
1301
+ raise HTTPException(
1136
1302
  status_code=status.HTTP_400_BAD_REQUEST,
1137
- content=output_content,
1303
+ detail=output_content,
1138
1304
  )
1139
1305
  user_id = local_dict_access_token_payload["user_id"]
1140
1306
 
@@ -1154,8 +1320,9 @@ async def update_password_v0(
1154
1320
  message=messages["INCORRECT_USER_ID"],
1155
1321
  log=f"incorrect user_id: {user_id}.",
1156
1322
  )
1157
- return JSONResponse(
1158
- status_code=status.HTTP_400_BAD_REQUEST, content=output_content
1323
+ raise HTTPException(
1324
+ status_code=status.HTTP_400_BAD_REQUEST,
1325
+ detail=output_content,
1159
1326
  )
1160
1327
 
1161
1328
  # validate password
@@ -1172,9 +1339,9 @@ async def update_password_v0(
1172
1339
  message=messages["INCORRECT_PASSWORD"],
1173
1340
  log=f"incorrect password for user_id {user_id}.",
1174
1341
  )
1175
- return JSONResponse(
1342
+ raise HTTPException(
1176
1343
  status_code=status.HTTP_400_BAD_REQUEST,
1177
- content=output_content,
1344
+ detail=output_content,
1178
1345
  )
1179
1346
  """
1180
1347
  main process
@@ -1205,6 +1372,7 @@ async def update_password_v0(
1205
1372
  )
1206
1373
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
1207
1374
  except HTTPException as http_exception:
1375
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
1208
1376
  return JSONResponse(
1209
1377
  status_code=http_exception.status_code, content=http_exception.detail
1210
1378
  )
@@ -1268,11 +1436,12 @@ async def validate_and_get_payload_from_token_v0(
1268
1436
  message=messages["INCORRECT_REFRESH_TOKEN"],
1269
1437
  log="refresh token valid but not present in database.",
1270
1438
  )
1271
- return JSONResponse(
1439
+ raise HTTPException(
1272
1440
  status_code=status.HTTP_400_BAD_REQUEST,
1273
- content=output_content,
1441
+ detail=output_content,
1274
1442
  )
1275
-
1443
+ except HTTPException as http_exception:
1444
+ raise
1276
1445
  except Exception as error:
1277
1446
  output_content = None
1278
1447
  if token_type == TokenType.access_token:
@@ -1284,9 +1453,9 @@ async def validate_and_get_payload_from_token_v0(
1284
1453
  message=messages["INCORRECT_REFRESH_TOKEN"], log=str(error)
1285
1454
  )
1286
1455
 
1287
- return JSONResponse(
1456
+ raise HTTPException(
1288
1457
  status_code=status.HTTP_400_BAD_REQUEST,
1289
- content=output_content,
1458
+ detail=output_content,
1290
1459
  )
1291
1460
 
1292
1461
  """
@@ -1302,6 +1471,7 @@ async def validate_and_get_payload_from_token_v0(
1302
1471
  )
1303
1472
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
1304
1473
  except HTTPException as http_exception:
1474
+ global_object_square_logger.logger.error(http_exception, exc_info=True)
1305
1475
  return JSONResponse(
1306
1476
  status_code=http_exception.status_code, content=http_exception.detail
1307
1477
  )
@@ -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.0.1
3
+ Version: 5.1.1
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,17 @@ pip install square_authentication
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v5.1.1
36
+
37
+ - add logger decorator in all functions.
38
+ - add error logs in all endpoints.
39
+
40
+ ### v5.1.0
41
+
42
+ - Core
43
+ - add logout/apps/v0.
44
+ - add logout/all/v0.
45
+
35
46
  ### v5.0.1
36
47
 
37
48
  - fix typo in return value of get_user_details_v0.
@@ -116,3 +127,4 @@ pip install square_authentication
116
127
 
117
128
  ## Feedback is appreciated. Thank you!
118
129
 
130
+