square-authentication 5.0.0__py3-none-any.whl → 5.1.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_authentication/pydantic_models/core.py +5 -1
- square_authentication/routes/core.py +157 -1
- {square_authentication-5.0.0.dist-info → square_authentication-5.1.0.dist-info}/METADATA +11 -1
- {square_authentication-5.0.0.dist-info → square_authentication-5.1.0.dist-info}/RECORD +6 -6
- {square_authentication-5.0.0.dist-info → square_authentication-5.1.0.dist-info}/WHEEL +0 -0
- {square_authentication-5.0.0.dist-info → square_authentication-5.1.0.dist-info}/top_level.txt +0 -0
@@ -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
|
|
@@ -322,7 +323,7 @@ async def get_user_details_v0(
|
|
322
323
|
],
|
323
324
|
"sessions": [
|
324
325
|
{
|
325
|
-
"
|
326
|
+
"app_name": [
|
326
327
|
y[App.app_name.name]
|
327
328
|
for y in local_list_app
|
328
329
|
if y[App.app_id.name] == x[UserApp.app_id.name]
|
@@ -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.
|
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
|
@@ -45,6 +45,16 @@ pip install square_authentication
|
|
45
45
|
|
46
46
|
## changelog
|
47
47
|
|
48
|
+
### v5.1.0
|
49
|
+
|
50
|
+
- Core
|
51
|
+
- add logout/apps/v0.
|
52
|
+
- add logout/all/v0.
|
53
|
+
|
54
|
+
### v5.0.1
|
55
|
+
|
56
|
+
- fix typo in return value of get_user_details_v0.
|
57
|
+
|
48
58
|
### v5.0.0
|
49
59
|
|
50
60
|
- change get_user_details_v0 to return app name instead of app ids.
|
@@ -4,14 +4,14 @@ square_authentication/main.py,sha256=95YgTBOuh2paWg3W0g0CvrQCeyTr0Q89fL14GmUxv2g
|
|
4
4
|
square_authentication/messages.py,sha256=BA9KC0vW9UD1ZXT4VneVqVNLlgdbMdsAwAgxhJISLf4,1175
|
5
5
|
square_authentication/data/config.ini,sha256=_740RvKpL5W2bUDGwZ7ePwuP-mAasr5cXXB81yq_Jv8,906
|
6
6
|
square_authentication/pydantic_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
-
square_authentication/pydantic_models/core.py,sha256=
|
7
|
+
square_authentication/pydantic_models/core.py,sha256=qeNETcJv7mnRKGhATOW2bg0NlHuyzvot1dZ1b1qqhwU,610
|
8
8
|
square_authentication/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
square_authentication/routes/core.py,sha256=
|
9
|
+
square_authentication/routes/core.py,sha256=ZeHpAwpAl3vdHSa6oisqH8XPHrQIZlJxNVJHfrs5Ob0,54794
|
10
10
|
square_authentication/routes/utility.py,sha256=ocLWj39JbKVOxgyTsM0xBUgTpHFmKIvvaT3UnjFvuOY,1783
|
11
11
|
square_authentication/utils/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
12
12
|
square_authentication/utils/encryption.py,sha256=T6BShoUr_xeGpbfPgTK-GxTlXPwcjwU4c4KW7KPzrF8,1865
|
13
13
|
square_authentication/utils/token.py,sha256=Y_arg5LegX-aprMj9YweUK8jjNZLGDjLUGgxbUA12w4,560
|
14
|
-
square_authentication-5.
|
15
|
-
square_authentication-5.
|
16
|
-
square_authentication-5.
|
17
|
-
square_authentication-5.
|
14
|
+
square_authentication-5.1.0.dist-info/METADATA,sha256=ySQXT0M6iBmuoCxptmYAN805tpbFZB-ERi48QsGCaJY,3746
|
15
|
+
square_authentication-5.1.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
16
|
+
square_authentication-5.1.0.dist-info/top_level.txt,sha256=wDssVJIl9KIEJPj5rR3rv4uRI7yCndMBrvHd_6BGXQA,22
|
17
|
+
square_authentication-5.1.0.dist-info/RECORD,,
|
File without changes
|
{square_authentication-5.0.0.dist-info → square_authentication-5.1.0.dist-info}/top_level.txt
RENAMED
File without changes
|