square-authentication 4.1.0__tar.gz → 4.2.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-4.1.0 → square_authentication-4.2.0}/PKG-INFO +5 -1
  2. {square_authentication-4.1.0 → square_authentication-4.2.0}/README.md +4 -0
  3. {square_authentication-4.1.0 → square_authentication-4.2.0}/setup.py +1 -1
  4. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/pydantic_models/core.py +6 -0
  5. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/routes/core.py +69 -0
  6. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication.egg-info/PKG-INFO +5 -1
  7. {square_authentication-4.1.0 → square_authentication-4.2.0}/setup.cfg +0 -0
  8. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/__init__.py +0 -0
  9. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/configuration.py +0 -0
  10. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/data/config.ini +0 -0
  11. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/main.py +0 -0
  12. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/messages.py +0 -0
  13. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/pydantic_models/__init__.py +0 -0
  14. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/routes/__init__.py +0 -0
  15. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/routes/utility.py +0 -0
  16. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/utils/__init__.py +0 -0
  17. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/utils/encryption.py +0 -0
  18. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication/utils/token.py +0 -0
  19. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication.egg-info/SOURCES.txt +0 -0
  20. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication.egg-info/dependency_links.txt +0 -0
  21. {square_authentication-4.1.0 → square_authentication-4.2.0}/square_authentication.egg-info/requires.txt +0 -0
  22. {square_authentication-4.1.0 → square_authentication-4.2.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: 4.1.0
3
+ Version: 4.2.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,10 @@ pip install square_authentication
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v4.2.0
36
+
37
+ - add validate_and_get_payload_from_token/v0 in core.
38
+
35
39
  ### v4.1.0
36
40
 
37
41
  - add get_text_hash/v0 in utils.
@@ -16,6 +16,10 @@ pip install square_authentication
16
16
 
17
17
  ## changelog
18
18
 
19
+ ### v4.2.0
20
+
21
+ - add validate_and_get_payload_from_token/v0 in core.
22
+
19
23
  ### v4.1.0
20
24
 
21
25
  - add get_text_hash/v0 in utils.
@@ -4,7 +4,7 @@ package_name = "square_authentication"
4
4
 
5
5
  setup(
6
6
  name=package_name,
7
- version="4.1.0",
7
+ version="4.2.0",
8
8
  packages=find_packages(),
9
9
  package_data={
10
10
  package_name: ["data/*"],
@@ -1,3 +1,4 @@
1
+ from enum import Enum
1
2
  from typing import Optional
2
3
 
3
4
  from pydantic import BaseModel
@@ -23,3 +24,8 @@ class DeleteUserV0(BaseModel):
23
24
  class UpdatePasswordV0(BaseModel):
24
25
  old_password: str
25
26
  new_password: str
27
+
28
+
29
+ class TokenType(Enum):
30
+ access_token = "access_token"
31
+ refresh_token = "refresh_token"
@@ -4,6 +4,7 @@ from typing import Annotated, List
4
4
  import bcrypt
5
5
  import jwt
6
6
  from fastapi import APIRouter, status, Header, HTTPException
7
+ from fastapi.params import Query
7
8
  from fastapi.responses import JSONResponse
8
9
  from requests import HTTPError
9
10
  from square_commons import get_api_output_in_standard_format
@@ -41,6 +42,7 @@ from square_authentication.pydantic_models.core import (
41
42
  LoginUsernameV0,
42
43
  DeleteUserV0,
43
44
  UpdatePasswordV0,
45
+ TokenType,
44
46
  )
45
47
  from square_authentication.utils.token import get_jwt_payload
46
48
 
@@ -1200,3 +1202,70 @@ async def update_password_v0(
1200
1202
  return JSONResponse(
1201
1203
  status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
1202
1204
  )
1205
+
1206
+
1207
+ @router.get("/validate_and_get_payload_from_token/v0")
1208
+ @global_object_square_logger.async_auto_logger
1209
+ async def validate_and_get_payload_from_token_v0(
1210
+ token: Annotated[str, Header()],
1211
+ token_type: TokenType = Query(...),
1212
+ ):
1213
+
1214
+ try:
1215
+ """
1216
+ validation
1217
+ """
1218
+ # validate token
1219
+ try:
1220
+ local_dict_token_payload = None
1221
+ if token_type == TokenType.access_token:
1222
+ local_dict_token_payload = get_jwt_payload(
1223
+ token, config_str_secret_key_for_access_token
1224
+ )
1225
+ elif token_type == TokenType.refresh_token:
1226
+ local_dict_token_payload = get_jwt_payload(
1227
+ token, config_str_secret_key_for_refresh_token
1228
+ )
1229
+ except Exception as error:
1230
+ output_content = None
1231
+ if token_type == TokenType.access_token:
1232
+ output_content = get_api_output_in_standard_format(
1233
+ message=messages["INCORRECT_ACCESS_TOKEN"], log=str(error)
1234
+ )
1235
+ elif token_type == TokenType.refresh_token:
1236
+ output_content = get_api_output_in_standard_format(
1237
+ message=messages["INCORRECT_REFRESH_TOKEN"], log=str(error)
1238
+ )
1239
+
1240
+ return JSONResponse(
1241
+ status_code=status.HTTP_400_BAD_REQUEST,
1242
+ content=output_content,
1243
+ )
1244
+
1245
+ """
1246
+ main process
1247
+ """
1248
+ # pass
1249
+ """
1250
+ return value
1251
+ """
1252
+ output_content = get_api_output_in_standard_format(
1253
+ message=messages["GENERIC_READ_SUCCESSFUL"], data=local_dict_token_payload
1254
+ )
1255
+ return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
1256
+ except HTTPException as http_exception:
1257
+ return JSONResponse(
1258
+ status_code=http_exception.status_code, content=http_exception.detail
1259
+ )
1260
+ except Exception as e:
1261
+ """
1262
+ rollback logic
1263
+ """
1264
+ global_object_square_logger.logger.error(e, exc_info=True)
1265
+ output_content = get_api_output_in_standard_format(
1266
+ message=messages["GENERIC_500"],
1267
+ log=str(e),
1268
+ )
1269
+ return JSONResponse(
1270
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
1271
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: square-authentication
3
- Version: 4.1.0
3
+ Version: 4.2.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,10 @@ pip install square_authentication
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v4.2.0
36
+
37
+ - add validate_and_get_payload_from_token/v0 in core.
38
+
35
39
  ### v4.1.0
36
40
 
37
41
  - add get_text_hash/v0 in utils.