square-authentication 5.0.1__tar.gz → 5.1.0__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.0}/PKG-INFO +7 -1
  2. {square_authentication-5.0.1 → square_authentication-5.1.0}/README.md +6 -0
  3. {square_authentication-5.0.1 → square_authentication-5.1.0}/setup.py +1 -1
  4. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/pydantic_models/core.py +5 -1
  5. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/routes/core.py +156 -0
  6. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication.egg-info/PKG-INFO +7 -1
  7. {square_authentication-5.0.1 → square_authentication-5.1.0}/setup.cfg +0 -0
  8. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/__init__.py +0 -0
  9. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/configuration.py +0 -0
  10. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/data/config.ini +0 -0
  11. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/main.py +0 -0
  12. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/messages.py +0 -0
  13. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/pydantic_models/__init__.py +0 -0
  14. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/routes/__init__.py +0 -0
  15. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/routes/utility.py +0 -0
  16. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/utils/__init__.py +0 -0
  17. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/utils/encryption.py +0 -0
  18. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication/utils/token.py +0 -0
  19. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication.egg-info/SOURCES.txt +0 -0
  20. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication.egg-info/dependency_links.txt +0 -0
  21. {square_authentication-5.0.1 → square_authentication-5.1.0}/square_authentication.egg-info/requires.txt +0 -0
  22. {square_authentication-5.0.1 → square_authentication-5.1.0}/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.0
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,12 @@ pip install square_authentication
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v5.1.0
36
+
37
+ - Core
38
+ - add logout/apps/v0.
39
+ - add logout/all/v0.
40
+
35
41
  ### v5.0.1
36
42
 
37
43
  - fix typo in return value of get_user_details_v0.
@@ -16,6 +16,12 @@ pip install square_authentication
16
16
 
17
17
  ## changelog
18
18
 
19
+ ### v5.1.0
20
+
21
+ - Core
22
+ - add logout/apps/v0.
23
+ - add logout/all/v0.
24
+
19
25
  ### v5.0.1
20
26
 
21
27
  - fix typo in return value of get_user_details_v0.
@@ -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.0",
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]
@@ -43,6 +43,7 @@ from square_authentication.pydantic_models.core import (
43
43
  DeleteUserV0,
44
44
  UpdatePasswordV0,
45
45
  TokenType,
46
+ LogoutAppsV0,
46
47
  )
47
48
  from square_authentication.utils.token import get_jwt_payload
48
49
 
@@ -891,6 +892,161 @@ async def logout_v0(
891
892
  )
892
893
 
893
894
 
895
+ @router.delete("/logout/apps/v0")
896
+ @global_object_square_logger.async_auto_logger
897
+ async def logout_apps_v0(
898
+ access_token: Annotated[str, Header()],
899
+ body: LogoutAppsV0,
900
+ ):
901
+ app_ids = body.app_ids
902
+ try:
903
+ """
904
+ validation
905
+ """
906
+ try:
907
+ local_dict_access_token_payload = get_jwt_payload(
908
+ access_token, config_str_secret_key_for_access_token
909
+ )
910
+ except Exception as error:
911
+ output_content = get_api_output_in_standard_format(
912
+ message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
913
+ )
914
+ return JSONResponse(
915
+ status_code=status.HTTP_400_BAD_REQUEST,
916
+ content=output_content,
917
+ )
918
+ user_id = local_dict_access_token_payload["user_id"]
919
+ # validate app_ids
920
+ app_ids = list(set(app_ids))
921
+ local_list_response_user_app = global_object_square_database_helper.get_rows_v0(
922
+ database_name=global_string_database_name,
923
+ schema_name=global_string_schema_name,
924
+ table_name=UserApp.__tablename__,
925
+ filters=FiltersV0(
926
+ root={
927
+ UserApp.user_id.name: FilterConditionsV0(eq=user_id),
928
+ }
929
+ ),
930
+ columns=[UserApp.app_id.name],
931
+ )["data"]["main"]
932
+ local_list_user_app_ids = [
933
+ x[UserApp.app_id.name] for x in local_list_response_user_app
934
+ ]
935
+ local_list_invalid_app_ids = [
936
+ x for x in app_ids if x not in local_list_user_app_ids
937
+ ]
938
+ if len(local_list_invalid_app_ids) > 0:
939
+ output_content = get_api_output_in_standard_format(
940
+ message=messages["GENERIC_400"],
941
+ log=f"invalid app_ids: {local_list_invalid_app_ids}.",
942
+ )
943
+ raise HTTPException(
944
+ status_code=status.HTTP_400_BAD_REQUEST,
945
+ detail=output_content,
946
+ )
947
+ """
948
+ main process
949
+ """
950
+ # delete session for user
951
+ global_object_square_database_helper.delete_rows_v0(
952
+ database_name=global_string_database_name,
953
+ schema_name=global_string_schema_name,
954
+ table_name=UserSession.__tablename__,
955
+ filters=FiltersV0(
956
+ root={
957
+ UserSession.user_id.name: FilterConditionsV0(eq=user_id),
958
+ UserSession.app_id.name: FilterConditionsV0(in_=app_ids),
959
+ }
960
+ ),
961
+ )
962
+ """
963
+ return value
964
+ """
965
+ output_content = get_api_output_in_standard_format(
966
+ message=messages["LOGOUT_SUCCESSFUL"],
967
+ )
968
+ return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
969
+ except HTTPException as http_exception:
970
+ return JSONResponse(
971
+ status_code=http_exception.status_code, content=http_exception.detail
972
+ )
973
+ except Exception as e:
974
+ """
975
+ rollback logic
976
+ """
977
+ global_object_square_logger.logger.error(e, exc_info=True)
978
+ output_content = get_api_output_in_standard_format(
979
+ message=messages["GENERIC_500"],
980
+ log=str(e),
981
+ )
982
+ return JSONResponse(
983
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
984
+ )
985
+
986
+
987
+ @router.delete("/logout/all/v0")
988
+ @global_object_square_logger.async_auto_logger
989
+ async def logout_all_v0(
990
+ access_token: Annotated[str, Header()],
991
+ ):
992
+
993
+ try:
994
+ """
995
+ validation
996
+ """
997
+ try:
998
+ local_dict_access_token_payload = get_jwt_payload(
999
+ access_token, config_str_secret_key_for_access_token
1000
+ )
1001
+ except Exception as error:
1002
+ output_content = get_api_output_in_standard_format(
1003
+ message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
1004
+ )
1005
+ return JSONResponse(
1006
+ status_code=status.HTTP_400_BAD_REQUEST,
1007
+ content=output_content,
1008
+ )
1009
+ user_id = local_dict_access_token_payload["user_id"]
1010
+
1011
+ """
1012
+ main process
1013
+ """
1014
+ # delete session for user
1015
+ global_object_square_database_helper.delete_rows_v0(
1016
+ database_name=global_string_database_name,
1017
+ schema_name=global_string_schema_name,
1018
+ table_name=UserSession.__tablename__,
1019
+ filters=FiltersV0(
1020
+ root={
1021
+ UserSession.user_id.name: FilterConditionsV0(eq=user_id),
1022
+ }
1023
+ ),
1024
+ )
1025
+ """
1026
+ return value
1027
+ """
1028
+ output_content = get_api_output_in_standard_format(
1029
+ message=messages["LOGOUT_SUCCESSFUL"],
1030
+ )
1031
+ return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
1032
+ except HTTPException as http_exception:
1033
+ return JSONResponse(
1034
+ status_code=http_exception.status_code, content=http_exception.detail
1035
+ )
1036
+ except Exception as e:
1037
+ """
1038
+ rollback logic
1039
+ """
1040
+ global_object_square_logger.logger.error(e, exc_info=True)
1041
+ output_content = get_api_output_in_standard_format(
1042
+ message=messages["GENERIC_500"],
1043
+ log=str(e),
1044
+ )
1045
+ return JSONResponse(
1046
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
1047
+ )
1048
+
1049
+
894
1050
  @router.patch("/update_username/v0")
895
1051
  @global_object_square_logger.async_auto_logger
896
1052
  async def update_username_v0(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: square-authentication
3
- Version: 5.0.1
3
+ Version: 5.1.0
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,12 @@ pip install square_authentication
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v5.1.0
36
+
37
+ - Core
38
+ - add logout/apps/v0.
39
+ - add logout/all/v0.
40
+
35
41
  ### v5.0.1
36
42
 
37
43
  - fix typo in return value of get_user_details_v0.