square-authentication 4.1.0__py3-none-any.whl → 4.2.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.
@@ -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
@@ -43,6 +43,10 @@ pip install square_authentication
43
43
 
44
44
  ## changelog
45
45
 
46
+ ### v4.2.0
47
+
48
+ - add validate_and_get_payload_from_token/v0 in core.
49
+
46
50
  ### v4.1.0
47
51
 
48
52
  - add get_text_hash/v0 in utils.
@@ -4,14 +4,14 @@ square_authentication/main.py,sha256=JK9KBmN73KL8EpKrXrjrwwf37bmC4AXrFHtfl2roYwQ
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=Hwzr-YJH6GVGLp4Z29iHItOEhiEvk65MjsttmCaDTe4,431
7
+ square_authentication/pydantic_models/core.py,sha256=D4Q76oBl9wTDe7DMq96Bryk6a0GpuZStoU4w_KXkAd0,548
8
8
  square_authentication/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- square_authentication/routes/core.py,sha256=Yki554LnBEv1RkwwPkSTksCbXMtgheka4_No41XVbe0,44742
9
+ square_authentication/routes/core.py,sha256=oc0zwDvE6RcmYkHrbhshBjfW-ZgvPH2kefPnTpyqtEY,47128
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-4.1.0.dist-info/METADATA,sha256=sLSqlgWDugaTf3y3APLXF9_xUDx5vO7CqmG6__hdr7c,2904
15
- square_authentication-4.1.0.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
16
- square_authentication-4.1.0.dist-info/top_level.txt,sha256=wDssVJIl9KIEJPj5rR3rv4uRI7yCndMBrvHd_6BGXQA,22
17
- square_authentication-4.1.0.dist-info/RECORD,,
14
+ square_authentication-4.2.0.dist-info/METADATA,sha256=982awnaEnVbeW8IBByfAgGOJ9EthybCmT6ikElJVZSA,2971
15
+ square_authentication-4.2.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
16
+ square_authentication-4.2.0.dist-info/top_level.txt,sha256=wDssVJIl9KIEJPj5rR3rv4uRI7yCndMBrvHd_6BGXQA,22
17
+ square_authentication-4.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.45.0)
2
+ Generator: bdist_wheel (0.45.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5