spakky-fastapi 0.7.17__py3-none-any.whl → 0.7.19__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.
@@ -31,6 +31,7 @@ IAuthenticatedFunction: TypeAlias = Callable[Concatenate[Any, JWT, P], Awaitable
31
31
  class JWTAuth(FunctionAnnotation):
32
32
  token_url: InitVar[str]
33
33
  authenticator: OAuth2PasswordBearer = field(init=False)
34
+ token_keywords: list[str] = field(init=False, default_factory=list)
34
35
 
35
36
  def __post_init__(self, token_url: str) -> None:
36
37
  self.authenticator = OAuth2PasswordBearer(tokenUrl=token_url)
@@ -38,10 +39,10 @@ class JWTAuth(FunctionAnnotation):
38
39
  def __call__(
39
40
  self, obj: IAuthenticatedFunction[P, R_co]
40
41
  ) -> IAuthenticatedFunction[P, R_co]:
41
- obj.__annotations__ = {
42
- k: Annotated[JWT, Depends(self.authenticator)] if v == JWT else v
43
- for k, v in obj.__annotations__.items()
44
- }
42
+ for key, value in obj.__annotations__.items():
43
+ if value == JWT:
44
+ obj.__annotations__[key] = Annotated[JWT, Depends(self.authenticator)]
45
+ self.token_keywords.append(key)
45
46
  return super().__call__(obj)
46
47
 
47
48
 
@@ -59,15 +60,17 @@ class AsyncJWTAuthAdvisor(IAsyncAdvisor):
59
60
 
60
61
  @Around(JWTAuth.contains)
61
62
  async def around_async(self, joinpoint: AsyncFunc, *args: Any, **kwargs: Any) -> Any:
62
- token: str = kwargs["token"]
63
- try:
64
- jwt: JWT = JWT(token=token)
65
- except (InvalidJWTFormatError, JWTDecodingError) as e:
66
- raise Unauthorized(AuthenticationFailedError()) from e
67
- if jwt.is_expired:
68
- raise Unauthorized(AuthenticationFailedError())
69
- if jwt.verify(self.__key) is False:
70
- raise Unauthorized(AuthenticationFailedError())
71
- self.__logger.info(f"[{type(self).__name__}] {jwt.payload!r}")
72
- kwargs["token"] = jwt
63
+ annotation: JWTAuth = JWTAuth.single(joinpoint)
64
+ for keyword in annotation.token_keywords:
65
+ token: str = kwargs[keyword]
66
+ try:
67
+ jwt: JWT = JWT(token=token)
68
+ except (InvalidJWTFormatError, JWTDecodingError) as e:
69
+ raise Unauthorized(AuthenticationFailedError()) from e
70
+ if jwt.is_expired:
71
+ raise Unauthorized(AuthenticationFailedError())
72
+ if jwt.verify(self.__key) is False:
73
+ raise Unauthorized(AuthenticationFailedError())
74
+ self.__logger.info(f"[{type(self).__name__}] {jwt.payload!r}")
75
+ kwargs[keyword] = jwt
73
76
  return await joinpoint(*args, **kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spakky-fastapi
3
- Version: 0.7.17
3
+ Version: 0.7.19
4
4
  Summary: Highly abstracted Framework core to use DDD & DI/IoC & AOP & Etc...
5
5
  Author: Spakky
6
6
  Author-email: sejong418@icloud.com
@@ -11,7 +11,7 @@ Classifier: Programming Language :: Python :: 3.11
11
11
  Classifier: Programming Language :: Python :: 3.12
12
12
  Requires-Dist: fastapi (>=0.109.2,<0.110.0)
13
13
  Requires-Dist: orjson (>=3.9.15,<4.0.0)
14
- Requires-Dist: spakky-core (>=0.7.13)
14
+ Requires-Dist: spakky-core (>=0.7.14)
15
15
  Requires-Dist: websockets (>=12.0,<13.0)
16
16
  Description-Content-Type: text/markdown
17
17
 
@@ -1,6 +1,6 @@
1
1
  spakky_fastapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  spakky_fastapi/error.py,sha256=SWyNZk1kxbTCiy-tLxB8saLpX5rBxwvy7q7JRCtNQV0,1124
3
- spakky_fastapi/jwt_auth.py,sha256=TugT_PzSc4LdjMvQp0NSytbah-AQRIvMis_b1XBOdmk,2553
3
+ spakky_fastapi/jwt_auth.py,sha256=Ug3DPEHQQn14gFb-j_o_NW0SUF-4NyfR67FLngjPCCQ,2822
4
4
  spakky_fastapi/middlewares/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  spakky_fastapi/middlewares/error_handling.py,sha256=w_zy4PtEdGkFNN79AHh7TfwWUGSQ1JFNvPo3Dy8ojDM,1325
6
6
  spakky_fastapi/post_processor.py,sha256=33czA6PLYzNxnwQ5dKz0fXjpM_7kyMf9kaY88b_GoCI,2889
@@ -8,6 +8,6 @@ spakky_fastapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  spakky_fastapi/routing.py,sha256=3OhnnDIzaDeNhuIMWpPG17--98ti6LsgdfENsWr332g,19181
9
9
  spakky_fastapi/stereotypes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  spakky_fastapi/stereotypes/api_controller.py,sha256=hLeIYM-olZHwvFZkd1joQ-5-OQAiZXznFu4CEhrcskk,196
11
- spakky_fastapi-0.7.17.dist-info/METADATA,sha256=fK62EcyHOMxJPVFOuFOm8qu4ftRJkWlbNPXCR_CdTvI,1702
12
- spakky_fastapi-0.7.17.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
13
- spakky_fastapi-0.7.17.dist-info/RECORD,,
11
+ spakky_fastapi-0.7.19.dist-info/METADATA,sha256=Epf3M5LlqNrHnnwrv0UDDnIuSKW4wRqo11C91P2BS38,1702
12
+ spakky_fastapi-0.7.19.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
13
+ spakky_fastapi-0.7.19.dist-info/RECORD,,