square-administration 2.1.0__py3-none-any.whl → 2.2.1__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.
@@ -12,4 +12,5 @@ messages = {
12
12
  "GENERIC_500": "an internal server error occurred. please try again later.",
13
13
  "INCORRECT_ACCESS_TOKEN": "the access token provided is invalid or expired.",
14
14
  "INCORRECT_REFRESH_TOKEN": "the refresh token provided is invalid or expired.",
15
+ "REFRESH_TOKEN_NOT_FOUND": "refresh token not found. please login again.",
15
16
  }
@@ -2,9 +2,10 @@ import json
2
2
  from typing import Annotated
3
3
 
4
4
  import bcrypt
5
- from fastapi import APIRouter, status, HTTPException, Header
5
+ from fastapi import APIRouter, status, HTTPException, Header, Request
6
6
  from fastapi.responses import JSONResponse
7
7
  from requests import HTTPError
8
+ from square_authentication_helper import TokenType
8
9
  from square_commons import get_api_output_in_standard_format
9
10
  from square_commons.api_utils import create_cookie
10
11
 
@@ -260,15 +261,39 @@ async def remove_app_for_self_v0(
260
261
 
261
262
  @router.delete("/logout/v0")
262
263
  @global_object_square_logger.async_auto_logger
263
- async def logout_v0(
264
- refresh_token: Annotated[str, Header()],
265
- ):
264
+ async def logout_v0(request: Request):
266
265
 
267
266
  try:
268
267
  """
269
268
  validation
270
269
  """
271
- # pass
270
+
271
+ refresh_token = request.cookies.get("refresh_token|" + str(global_int_app_id))
272
+ if refresh_token is None:
273
+ output_content = get_api_output_in_standard_format(
274
+ message=messages["REFRESH_TOKEN_NOT_FOUND"],
275
+ log=f"refresh token not found.",
276
+ )
277
+ return JSONResponse(
278
+ status_code=status.HTTP_400_BAD_REQUEST,
279
+ content=output_content,
280
+ )
281
+ refresh_token_payload = global_object_square_authentication_helper.validate_and_get_payload_from_token_v0(
282
+ refresh_token, TokenType.refresh_token
283
+ )[
284
+ "data"
285
+ ][
286
+ "main"
287
+ ]
288
+ if refresh_token_payload["app_id"] != global_int_app_id:
289
+ output_content = get_api_output_in_standard_format(
290
+ message=messages["INCORRECT_REFRESH_TOKEN"],
291
+ log=f"refresh token is for different app id. intended app id: {global_int_app_id}, actual app id: {refresh_token_payload['app_id']}.",
292
+ )
293
+ return JSONResponse(
294
+ status_code=status.HTTP_400_BAD_REQUEST,
295
+ content=output_content,
296
+ )
272
297
  """
273
298
  main process
274
299
  """
@@ -320,14 +345,39 @@ async def logout_v0(
320
345
  @router.get("/generate_access_token/v0")
321
346
  @global_object_square_logger.async_auto_logger
322
347
  async def generate_access_token_v0(
323
- refresh_token: Annotated[str, Header()],
348
+ request: Request,
324
349
  ):
325
350
 
326
351
  try:
327
352
  """
328
353
  validation
329
354
  """
330
- # pass
355
+ refresh_token = request.cookies.get("refresh_token|" + str(global_int_app_id))
356
+ if refresh_token is None:
357
+ output_content = get_api_output_in_standard_format(
358
+ message=messages["REFRESH_TOKEN_NOT_FOUND"],
359
+ log=f"refresh token not found.",
360
+ )
361
+ return JSONResponse(
362
+ status_code=status.HTTP_400_BAD_REQUEST,
363
+ content=output_content,
364
+ )
365
+ refresh_token_payload = global_object_square_authentication_helper.validate_and_get_payload_from_token_v0(
366
+ refresh_token, TokenType.refresh_token
367
+ )[
368
+ "data"
369
+ ][
370
+ "main"
371
+ ]
372
+ if refresh_token_payload["app_id"] != global_int_app_id:
373
+ output_content = get_api_output_in_standard_format(
374
+ message=messages["INCORRECT_REFRESH_TOKEN"],
375
+ log=f"refresh token is for different app id. intended app id: {global_int_app_id}, actual app id: {refresh_token_payload['app_id']}.",
376
+ )
377
+ return JSONResponse(
378
+ status_code=status.HTTP_400_BAD_REQUEST,
379
+ content=output_content,
380
+ )
331
381
  """
332
382
  main process
333
383
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: square-administration
3
- Version: 2.1.0
3
+ Version: 2.2.1
4
4
  Summary: common business layer for my personal server.
5
5
  Home-page: https://github.com/thepmsquare/square_administration
6
6
  Author: thePmSquare
@@ -42,6 +42,16 @@ pip install square_administration
42
42
 
43
43
  ## changelog
44
44
 
45
+ ### v2.2.1
46
+
47
+ - authentication
48
+ - add validation for refresh token app id in logout_v0, generate_access_token_v0.
49
+
50
+ ### v2.2.0
51
+
52
+ - authentication
53
+ - logout_v0, generate_access_token_v0 remove refresh token from request header and accept in cookie.
54
+
45
55
  ### v2.1.0
46
56
 
47
57
  - add authentication -> logout_v0, generate_access_token_v0.
@@ -1,16 +1,16 @@
1
1
  square_administration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  square_administration/configuration.py,sha256=ldSmVp3FWOndN4u-dH-pf4i0olRZx1-uORJAj1qW-g8,4733
3
3
  square_administration/main.py,sha256=L4MM_7yimRLB8J1ltgXPnrN3j_UXKVtp8o8S46MSqrY,1678
4
- square_administration/messages.py,sha256=93dzwW2J3romvGl66OGBt3z2ueGnInMz28pem9egnaw,984
4
+ square_administration/messages.py,sha256=VYjJGW0Kvtjrx1Mw7ekksLVMoxcexLol2OckvqhZ3n0,1063
5
5
  square_administration/data/config.ini,sha256=NMpUnBSPEdwCW1Y-z5DOjpTQgXGjt4ZcqP4QQiAXr_U,997
6
6
  square_administration/pydantic_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  square_administration/pydantic_models/authentication.py,sha256=DWXctw5UWzkSVY7nMIQZsRhmgW3OK455OVcoUpJrPY0,202
8
8
  square_administration/pydantic_models/core.py,sha256=HUMrBmfKrXeL-126gE5j2povdVmktn8XLg2tHEdeXTk,344
9
9
  square_administration/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- square_administration/routes/authentication.py,sha256=KSj8oWB3Jw7caVP1z1OoWbQAdawvS04P-4xT2OmzPyo,11029
10
+ square_administration/routes/authentication.py,sha256=V1NZgee3IvQNzCjP4TdVDc-7sWNd2m7EjG1d3m-C7Yw,13383
11
11
  square_administration/routes/core.py,sha256=65_FIZilintZvbHx7r25UQbgN-oKdQ92-Nv3kpwKX6s,5374
12
12
  square_administration/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- square_administration-2.1.0.dist-info/METADATA,sha256=HAb400ntVv1QSFh6au4oi08tklXJkAUq0FYJvef0Lls,1551
14
- square_administration-2.1.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
15
- square_administration-2.1.0.dist-info/top_level.txt,sha256=8WFipDrMQUPRDo5AvipxU1YK3wZtWZyCUMWaR416zAw,22
16
- square_administration-2.1.0.dist-info/RECORD,,
13
+ square_administration-2.2.1.dist-info/METADATA,sha256=ygKKKDOhbGQUhkk2Caj2RfxtHB559qM43Q7VQoubMzk,1802
14
+ square_administration-2.2.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
15
+ square_administration-2.2.1.dist-info/top_level.txt,sha256=8WFipDrMQUPRDo5AvipxU1YK3wZtWZyCUMWaR416zAw,22
16
+ square_administration-2.2.1.dist-info/RECORD,,