fastapi-factory-utilities 0.7.1__py3-none-any.whl → 0.8.3__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.
Potentially problematic release.
This version of fastapi-factory-utilities might be problematic. Click here for more details.
- fastapi_factory_utilities/core/exceptions.py +23 -15
- fastapi_factory_utilities/core/plugins/aiopika/exchange.py +4 -5
- fastapi_factory_utilities/core/plugins/aiopika/listener/abstract.py +4 -4
- fastapi_factory_utilities/core/plugins/aiopika/message.py +4 -4
- fastapi_factory_utilities/core/plugins/aiopika/queue.py +2 -0
- fastapi_factory_utilities/core/plugins/taskiq_plugins/__init__.py +2 -0
- fastapi_factory_utilities/core/security/__init__.py +5 -0
- fastapi_factory_utilities/core/security/abstracts.py +42 -0
- fastapi_factory_utilities/core/security/jwt/__init__.py +45 -0
- fastapi_factory_utilities/core/security/jwt/configs.py +32 -0
- fastapi_factory_utilities/core/security/jwt/decoders.py +130 -0
- fastapi_factory_utilities/core/security/jwt/exceptions.py +23 -0
- fastapi_factory_utilities/core/security/jwt/objects.py +107 -0
- fastapi_factory_utilities/core/security/jwt/services.py +176 -0
- fastapi_factory_utilities/core/security/jwt/stores.py +43 -0
- fastapi_factory_utilities/core/security/jwt/types.py +9 -0
- fastapi_factory_utilities/core/security/jwt/verifiers.py +46 -0
- fastapi_factory_utilities/core/security/kratos.py +43 -43
- fastapi_factory_utilities/core/services/hydra/__init__.py +10 -3
- fastapi_factory_utilities/core/services/hydra/services.py +112 -34
- fastapi_factory_utilities/core/services/status/exceptions.py +1 -1
- {fastapi_factory_utilities-0.7.1.dist-info → fastapi_factory_utilities-0.8.3.dist-info}/METADATA +1 -1
- {fastapi_factory_utilities-0.7.1.dist-info → fastapi_factory_utilities-0.8.3.dist-info}/RECORD +26 -16
- fastapi_factory_utilities/core/security/jwt.py +0 -159
- {fastapi_factory_utilities-0.7.1.dist-info → fastapi_factory_utilities-0.8.3.dist-info}/WHEEL +0 -0
- {fastapi_factory_utilities-0.7.1.dist-info → fastapi_factory_utilities-0.8.3.dist-info}/entry_points.txt +0 -0
- {fastapi_factory_utilities-0.7.1.dist-info → fastapi_factory_utilities-0.8.3.dist-info}/licenses/LICENSE +0 -0
{fastapi_factory_utilities-0.7.1.dist-info → fastapi_factory_utilities-0.8.3.dist-info}/RECORD
RENAMED
|
@@ -12,7 +12,7 @@ fastapi_factory_utilities/core/app/config.py,sha256=MuV4G_M4QgZWYHoulusJLv_m4Qr2
|
|
|
12
12
|
fastapi_factory_utilities/core/app/enums.py,sha256=X1upnaehYU0eHExXTde5xsH-pI9q7HZDNsOEF5PApdg,226
|
|
13
13
|
fastapi_factory_utilities/core/app/exceptions.py,sha256=tQDf0_4j5xgCbku7TL7JaZGs3_bjsWG2YLBCydQJpPw,664
|
|
14
14
|
fastapi_factory_utilities/core/app/fastapi_builder.py,sha256=7egWkS98nTiVBe2Bw5dQzDBryQCkz4w7gnY9HA24NFg,2855
|
|
15
|
-
fastapi_factory_utilities/core/exceptions.py,sha256=
|
|
15
|
+
fastapi_factory_utilities/core/exceptions.py,sha256=JeGUBiEC0dsS1uObP5SuJgUu_aCF5lCDdEFTL0Eq4W4,3221
|
|
16
16
|
fastapi_factory_utilities/core/plugins/__init__.py,sha256=7ctIv2Jx2uOUpgm8ITFRuZxHi6OXvlVS0VcbszVzvis,114
|
|
17
17
|
fastapi_factory_utilities/core/plugins/abstracts.py,sha256=p5iXmeOVD737G73I2keKV0Y-jLGQf2vYbTSR1LgrA14,1165
|
|
18
18
|
fastapi_factory_utilities/core/plugins/aiopika/__init__.py,sha256=flXanbhbjFaOsgx7jZvtW0bVLT_NXHypIPFO1tIHoCM,705
|
|
@@ -20,14 +20,14 @@ fastapi_factory_utilities/core/plugins/aiopika/abstract.py,sha256=TcvDwdaLV0UqFH
|
|
|
20
20
|
fastapi_factory_utilities/core/plugins/aiopika/configs.py,sha256=BEPE8Ss7q_yCyuii4nywmIgh67iNLdhKxUm8tC0PdCY,3706
|
|
21
21
|
fastapi_factory_utilities/core/plugins/aiopika/depends.py,sha256=5xna571hCIdqzbo0t1CW-yzmJMSpEw_KUeJh5nBXjwQ,761
|
|
22
22
|
fastapi_factory_utilities/core/plugins/aiopika/exceptions.py,sha256=AkBKT8HVPpJDAntLNlOLp6lpQpKI-k8gxNzU24FsOF0,985
|
|
23
|
-
fastapi_factory_utilities/core/plugins/aiopika/exchange.py,sha256=
|
|
23
|
+
fastapi_factory_utilities/core/plugins/aiopika/exchange.py,sha256=MxASHfkIwFPAvIoRhGAXkzfsOPBAm5JfLkivcQtLvds,2501
|
|
24
24
|
fastapi_factory_utilities/core/plugins/aiopika/listener/__init__.py,sha256=LsTyu6kGoUm7c5OvSQTDJL7d8CG9TeARBHHVe_HGsHY,148
|
|
25
|
-
fastapi_factory_utilities/core/plugins/aiopika/listener/abstract.py,sha256=
|
|
26
|
-
fastapi_factory_utilities/core/plugins/aiopika/message.py,sha256=
|
|
25
|
+
fastapi_factory_utilities/core/plugins/aiopika/listener/abstract.py,sha256=XGYfm3bZSJHG1B97tS9GqK3V9gZ3EpTEVcHyF0L9Xtc,2618
|
|
26
|
+
fastapi_factory_utilities/core/plugins/aiopika/message.py,sha256=y1tEhJWOXg1R7y7iA6F1VSZccsRPBB01IMYuU9BfikA,2885
|
|
27
27
|
fastapi_factory_utilities/core/plugins/aiopika/plugins.py,sha256=0lLYt-ZG3g3m8wi1tCCPEhTUBqaXuEJOwHEcrvP7FYc,3284
|
|
28
28
|
fastapi_factory_utilities/core/plugins/aiopika/publisher/__init__.py,sha256=MGGdygH72xHZ4QAwvbUZKQt-_mPzLmMxHyAACSNnZ_c,151
|
|
29
29
|
fastapi_factory_utilities/core/plugins/aiopika/publisher/abstract.py,sha256=PmIG5zlx-tFUAneHtbknR0Ik5flz8pMTzxcreY2hZ7s,2494
|
|
30
|
-
fastapi_factory_utilities/core/plugins/aiopika/queue.py,sha256=
|
|
30
|
+
fastapi_factory_utilities/core/plugins/aiopika/queue.py,sha256=VivCbsIgqM36P_7VTZdOZ9kGop2m0kPCvDVQ1nEJCTo,2874
|
|
31
31
|
fastapi_factory_utilities/core/plugins/odm_plugin/__init__.py,sha256=JsVz4GBiZRmm4qpUD1-Wsg2tRXTn-VO5fU-W1whZo4E,683
|
|
32
32
|
fastapi_factory_utilities/core/plugins/odm_plugin/builder.py,sha256=MdO1D0C9LQpoqtNFqgPwSYedLzXR6PArhkoJw6wzykg,8761
|
|
33
33
|
fastapi_factory_utilities/core/plugins/odm_plugin/configs.py,sha256=5bVbtsLwJhuIvt8FCzOvk002G8qFmZumWkN75bPKatc,331
|
|
@@ -44,19 +44,29 @@ fastapi_factory_utilities/core/plugins/opentelemetry_plugin/exceptions.py,sha256
|
|
|
44
44
|
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/helpers.py,sha256=qpTIzX67orJz7vy6SBIwRs24omMBoToJkhpurZRjPuk,1533
|
|
45
45
|
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/instruments/__init__.py,sha256=lMtdd1DSDrFcXggf0qMpB1RJC7aBqWMpOBXxC8-bqPY,3307
|
|
46
46
|
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/plugins.py,sha256=v9W4bqEljcRgeSL8pf-4yZ7SGXOFmxVoljthvcLdy6Q,5356
|
|
47
|
-
fastapi_factory_utilities/core/plugins/taskiq_plugins/__init__.py,sha256=
|
|
47
|
+
fastapi_factory_utilities/core/plugins/taskiq_plugins/__init__.py,sha256=zLZh8HU-oY1FL977yXt51AV95p8WCBJY2cleVUU7w6M,850
|
|
48
48
|
fastapi_factory_utilities/core/plugins/taskiq_plugins/configs.py,sha256=O2rgFFWJNBUZ7ozfhM0Lj5Te-58qBNrQtw_N0mosAu4,304
|
|
49
49
|
fastapi_factory_utilities/core/plugins/taskiq_plugins/depends.py,sha256=XBxC1uUdMhYtqZDqmUEKI80y5L7mDoXXjN8dZjEvVAo,1602
|
|
50
50
|
fastapi_factory_utilities/core/plugins/taskiq_plugins/exceptions.py,sha256=1Xq_DqDFiQm2YU-2pGxziy-EeMhHiUsUwV0XdY_rQls,456
|
|
51
51
|
fastapi_factory_utilities/core/plugins/taskiq_plugins/plugin.py,sha256=gUlU2s7aLB2lkAAPdLqVc-BY16PessSYTGMGgNcKCSA,1602
|
|
52
52
|
fastapi_factory_utilities/core/plugins/taskiq_plugins/schedulers.py,sha256=82Yh7Y_MUxiWjrHPnsW_Ax-CWREAT6eC_bVl-HW5a3E,7208
|
|
53
53
|
fastapi_factory_utilities/core/protocols.py,sha256=w5FQqMAZ_OulG5hQWkoOapNSnxsjBPq4EjvWNXXdI_c,859
|
|
54
|
-
fastapi_factory_utilities/core/security/
|
|
55
|
-
fastapi_factory_utilities/core/security/
|
|
56
|
-
fastapi_factory_utilities/core/
|
|
54
|
+
fastapi_factory_utilities/core/security/__init__.py,sha256=C_EnEZLMrhmAktNmSD80-0eqhs38AFnTmp-3UC7L0cg,119
|
|
55
|
+
fastapi_factory_utilities/core/security/abstracts.py,sha256=xas-gFTqWzxWMZNZx4qdtAzYW_XA8vH2N1wlBx0CuN8,1247
|
|
56
|
+
fastapi_factory_utilities/core/security/jwt/__init__.py,sha256=sx67ZrineeJoaTT-yeh0236Ynq6FdXuUuAQiMXEVh6I,1241
|
|
57
|
+
fastapi_factory_utilities/core/security/jwt/configs.py,sha256=FaqBXdH3W1e95DrFl1QMqF6Teyp5ZvGq42EC8GCwGNM,1367
|
|
58
|
+
fastapi_factory_utilities/core/security/jwt/decoders.py,sha256=byj--PbnVbBHrZm6lWE2SH3XX37zPuWdujcLgogdB1U,4935
|
|
59
|
+
fastapi_factory_utilities/core/security/jwt/exceptions.py,sha256=9kxA4JLq9tfBfnwf-Wadpy9RiU8IjcijifqUS8KFhz0,642
|
|
60
|
+
fastapi_factory_utilities/core/security/jwt/objects.py,sha256=z4geVMnrZVPV0aaf-p0NIY4WHXhQox2UiKyHTHH5DOc,3986
|
|
61
|
+
fastapi_factory_utilities/core/security/jwt/services.py,sha256=8NAXI8RniXZAzNJzg8I9nisu5ch8fP83c9Tm-vdM4p8,7240
|
|
62
|
+
fastapi_factory_utilities/core/security/jwt/stores.py,sha256=LhAAputlPFBZyVMhm5blHKX6eKYo_GxrULANgYBWKio,1193
|
|
63
|
+
fastapi_factory_utilities/core/security/jwt/types.py,sha256=FO9fIDh67pK0iVzQGeH_M9AWRqCQQS2S7GqkHkZBQBo,288
|
|
64
|
+
fastapi_factory_utilities/core/security/jwt/verifiers.py,sha256=bf6nlm3dCk4Ej1ncB-gfIRRXc5I5np9IzAo1vDhwo1c,1292
|
|
65
|
+
fastapi_factory_utilities/core/security/kratos.py,sha256=Nfol2sIHlRSw5JdzzFsa89_C15lrLLQMeUd55QAGZDc,3193
|
|
66
|
+
fastapi_factory_utilities/core/services/hydra/__init__.py,sha256=b6q22Qiapcg4xzoWNI5_qyT5wwcRJ7hiK1ItGmspgW8,616
|
|
57
67
|
fastapi_factory_utilities/core/services/hydra/exceptions.py,sha256=ePMrfZturU2IVcxOebR0CbVKKqprce_fK-4UXbPPgNI,450
|
|
58
68
|
fastapi_factory_utilities/core/services/hydra/objects.py,sha256=2CeV_4zmwwpfbXQ0TM9B_UnNkZuIRXweFP_VALBo57c,601
|
|
59
|
-
fastapi_factory_utilities/core/services/hydra/services.py,sha256=
|
|
69
|
+
fastapi_factory_utilities/core/services/hydra/services.py,sha256=JvRyAW7J5zG-r4hE6Y0VzeQZuOcwfjU4eGgo6k_bqJg,8235
|
|
60
70
|
fastapi_factory_utilities/core/services/kratos/__init__.py,sha256=DaC29-Ol0WR5vX56IHLGDXP9UrhISq0Juhg_sJTasw4,368
|
|
61
71
|
fastapi_factory_utilities/core/services/kratos/enums.py,sha256=ULJppowlZbOjdnUIXQyI4_nHmHZoNnv7-M1CYQBYXFY,220
|
|
62
72
|
fastapi_factory_utilities/core/services/kratos/exceptions.py,sha256=xAX01-lQvPpADgcwhB5YWSy1UqAxG38s2rlU9AJBJd8,472
|
|
@@ -64,7 +74,7 @@ fastapi_factory_utilities/core/services/kratos/objects.py,sha256=a0npt4Q6d9UbF0w
|
|
|
64
74
|
fastapi_factory_utilities/core/services/kratos/services.py,sha256=RFKrME6M6omWiHORMBCSyvIG0BsimQaCfnmtsOdFfsg,3158
|
|
65
75
|
fastapi_factory_utilities/core/services/status/__init__.py,sha256=kkR2Xx-kbHb_QXkkBSUNIK5y_eNM4YCElFftBAooIY0,370
|
|
66
76
|
fastapi_factory_utilities/core/services/status/enums.py,sha256=IUxWAd0Ecknri4BqzaqoDRRhT_8LdcgtQcNqgNVDXGE,599
|
|
67
|
-
fastapi_factory_utilities/core/services/status/exceptions.py,sha256=
|
|
77
|
+
fastapi_factory_utilities/core/services/status/exceptions.py,sha256=nA22c9djJMTRh_uN2WD0iKs-wRLZ09hhdPEx3slt1Bw,840
|
|
68
78
|
fastapi_factory_utilities/core/services/status/health_calculator_strategies.py,sha256=p2KKJo-dq1j9iWHT0mvlBKtldH9m8l31aytLkUsb9nQ,1634
|
|
69
79
|
fastapi_factory_utilities/core/services/status/readiness_calculator_strategies.py,sha256=hA1LX2pSxva-7bVaQ0dw8NpTbl1ZWDtXd9xzqQUGUsI,1354
|
|
70
80
|
fastapi_factory_utilities/core/services/status/services.py,sha256=qtgYdnxNQMbb6q6G9uGasRO3lZcpiWNmw1padPkh6jA,8490
|
|
@@ -94,8 +104,8 @@ fastapi_factory_utilities/example/models/books/repository.py,sha256=7K63uAsSEGZ2
|
|
|
94
104
|
fastapi_factory_utilities/example/services/books/__init__.py,sha256=Z06yNRoA7Zg3TGN-Q9rrvJg6Bbx-qJw661MVwukV6vQ,148
|
|
95
105
|
fastapi_factory_utilities/example/services/books/services.py,sha256=-x7d4hotUWLzWo5uImMjFmtNcSTHwWv2bfttIbYYKbA,5380
|
|
96
106
|
fastapi_factory_utilities/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
97
|
-
fastapi_factory_utilities-0.
|
|
98
|
-
fastapi_factory_utilities-0.
|
|
99
|
-
fastapi_factory_utilities-0.
|
|
100
|
-
fastapi_factory_utilities-0.
|
|
101
|
-
fastapi_factory_utilities-0.
|
|
107
|
+
fastapi_factory_utilities-0.8.3.dist-info/METADATA,sha256=kQWq2Cic5RUJkWWLxtQUpDv-whv2JEUJ9zIpRM2kSIc,3741
|
|
108
|
+
fastapi_factory_utilities-0.8.3.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
109
|
+
fastapi_factory_utilities-0.8.3.dist-info/entry_points.txt,sha256=IK0VcBexXo4uXQmTrbfhhnnfq4GmXPRn0GBB8hzlsq4,101
|
|
110
|
+
fastapi_factory_utilities-0.8.3.dist-info/licenses/LICENSE,sha256=iO1nLzMMst6vEiqgSUrfrbetM7b0bvdzXhbed5tqG8o,1074
|
|
111
|
+
fastapi_factory_utilities-0.8.3.dist-info/RECORD,,
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
"""Provides security-related functions for the API."""
|
|
2
|
-
|
|
3
|
-
from asyncio import Task, TaskGroup
|
|
4
|
-
from http import HTTPStatus
|
|
5
|
-
from typing import Any, ClassVar, NewType, cast
|
|
6
|
-
|
|
7
|
-
import jwt
|
|
8
|
-
import pydantic
|
|
9
|
-
from fastapi import Request
|
|
10
|
-
from fastapi.exceptions import HTTPException
|
|
11
|
-
from pydantic import BaseModel
|
|
12
|
-
|
|
13
|
-
Scope = NewType("Scope", str)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class JWTBearerDecoded(BaseModel):
|
|
17
|
-
"""JWT bearer token decoded."""
|
|
18
|
-
|
|
19
|
-
model_config: ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
20
|
-
arbitrary_types_allowed=True,
|
|
21
|
-
extra="forbid",
|
|
22
|
-
frozen=True,
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
scopes: list[str] | None = None
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class JWTBearerAuthentication:
|
|
29
|
-
"""JWT Bearer Authentication.
|
|
30
|
-
|
|
31
|
-
This class is used to authenticate users using JWT tokens.
|
|
32
|
-
It extracts the token from the request, decodes it, and verifies its validity.
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
def __init__(self, scopes: list[Scope] | None = None, jwt_raw: str | None = None) -> None:
|
|
36
|
-
"""Initialize the OAuth2 class.
|
|
37
|
-
|
|
38
|
-
Args:
|
|
39
|
-
scopes (SecurityScopes): Security scopes for the OAuth2.
|
|
40
|
-
jwt_raw (str): JWT token to be used for authentication.
|
|
41
|
-
"""
|
|
42
|
-
self.jwt_raw: str | None = jwt_raw
|
|
43
|
-
self.scopes: list[Scope] | None = scopes
|
|
44
|
-
|
|
45
|
-
def _extract_raw_token(self, request: Request) -> str:
|
|
46
|
-
"""Extract the raw token from the request.
|
|
47
|
-
|
|
48
|
-
Args:
|
|
49
|
-
request (Request): FastAPI request object.
|
|
50
|
-
|
|
51
|
-
Returns:
|
|
52
|
-
str: Raw token.
|
|
53
|
-
|
|
54
|
-
Raises:
|
|
55
|
-
HTTPException: If the token is missing or invalid.
|
|
56
|
-
"""
|
|
57
|
-
try:
|
|
58
|
-
authorization_header: str | None = request.headers.get("Authorization")
|
|
59
|
-
except (AttributeError, KeyError) as e:
|
|
60
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Missing Credentials") from e
|
|
61
|
-
|
|
62
|
-
if not authorization_header:
|
|
63
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Missing Credentials")
|
|
64
|
-
|
|
65
|
-
if not authorization_header.startswith("Bearer "):
|
|
66
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Invalid Credentials")
|
|
67
|
-
|
|
68
|
-
return authorization_header.split(sep=" ")[1]
|
|
69
|
-
|
|
70
|
-
async def _decode_jwt(self, jwt_raw: str) -> JWTBearerDecoded:
|
|
71
|
-
"""Decode the JWT token.
|
|
72
|
-
|
|
73
|
-
Args:
|
|
74
|
-
jwt_raw (str): Raw JWT token.
|
|
75
|
-
|
|
76
|
-
Returns:
|
|
77
|
-
JWTBearerDecoded: Decoded JWT token.
|
|
78
|
-
|
|
79
|
-
Raises:
|
|
80
|
-
HTTPException: If the token is invalid or expired.
|
|
81
|
-
"""
|
|
82
|
-
try:
|
|
83
|
-
jwt_decoded: dict[str, Any] = cast(
|
|
84
|
-
dict[str, Any],
|
|
85
|
-
jwt.decode(
|
|
86
|
-
jwt=jwt_raw,
|
|
87
|
-
algorithms=["HS256", "RS256"],
|
|
88
|
-
options={"verify_signature": True},
|
|
89
|
-
),
|
|
90
|
-
)
|
|
91
|
-
return JWTBearerDecoded(**jwt_decoded)
|
|
92
|
-
except jwt.ExpiredSignatureError as e:
|
|
93
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Token expired") from e
|
|
94
|
-
except jwt.InvalidTokenError as e:
|
|
95
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Invalid token") from e
|
|
96
|
-
except pydantic.ValidationError as e:
|
|
97
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail=f"Invalid token: {e.json()}") from e
|
|
98
|
-
|
|
99
|
-
async def _verify(self, jwt_raw: str) -> None:
|
|
100
|
-
"""Verify the JWT token.
|
|
101
|
-
|
|
102
|
-
Args:
|
|
103
|
-
jwt_raw (str): Raw JWT token.
|
|
104
|
-
"""
|
|
105
|
-
pass
|
|
106
|
-
|
|
107
|
-
def _has_scope(self, jwt_decoded: JWTBearerDecoded) -> None:
|
|
108
|
-
"""Check if the JWT token has the required scope.
|
|
109
|
-
|
|
110
|
-
Args:
|
|
111
|
-
jwt_decoded (JWTBearerDecoded): Decoded JWT token.
|
|
112
|
-
|
|
113
|
-
"""
|
|
114
|
-
# Just Authentication (no scopes, no authorization)
|
|
115
|
-
if not self.scopes:
|
|
116
|
-
return
|
|
117
|
-
# JWT without scopes (no authorization)
|
|
118
|
-
if not jwt_decoded.scopes:
|
|
119
|
-
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Unauthorized")
|
|
120
|
-
# Check if all required scopes are present
|
|
121
|
-
if not all(scope in jwt_decoded.scopes for scope in (self.scopes or [])):
|
|
122
|
-
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Unauthorized")
|
|
123
|
-
|
|
124
|
-
# All scopes are valid (authorization)
|
|
125
|
-
return
|
|
126
|
-
|
|
127
|
-
async def __call__(self, request: Request | None = None) -> JWTBearerDecoded:
|
|
128
|
-
"""Call the JWT bearer authentication.
|
|
129
|
-
|
|
130
|
-
Args:
|
|
131
|
-
request (Request): FastAPI request object.
|
|
132
|
-
|
|
133
|
-
Returns:
|
|
134
|
-
JWTBearerDecoded: Decoded JWT token.
|
|
135
|
-
|
|
136
|
-
Raises:
|
|
137
|
-
HTTPException: If the token is missing or invalid.
|
|
138
|
-
"""
|
|
139
|
-
# Ensure that the jwt will be provided
|
|
140
|
-
# by the request or by the jwt parameter
|
|
141
|
-
if self.jwt_raw is None and request is None:
|
|
142
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Missing Credentials")
|
|
143
|
-
jwt_raw: str
|
|
144
|
-
if self.jwt_raw is None:
|
|
145
|
-
jwt_raw = self._extract_raw_token(request=request) # type: ignore[arg-type]
|
|
146
|
-
else:
|
|
147
|
-
jwt_raw = self.jwt_raw
|
|
148
|
-
|
|
149
|
-
# Execute the io bound and cpu bound tasks in parallel
|
|
150
|
-
async with TaskGroup() as tg:
|
|
151
|
-
# TODO: Can be disabled by configuration (for operation purposes)
|
|
152
|
-
# Ensure that the jwt is not revoked or expired
|
|
153
|
-
tg.create_task(self._verify(jwt_raw=jwt_raw), name="verify_jwt")
|
|
154
|
-
# Ensure that the jwt is not altered or expired
|
|
155
|
-
task_decode: Task[Any] = tg.create_task(self._decode_jwt(jwt_raw=jwt_raw), name="decode_jwt")
|
|
156
|
-
# Scope Validation
|
|
157
|
-
jwt_decoded: JWTBearerDecoded = task_decode.result()
|
|
158
|
-
self._has_scope(jwt_decoded=jwt_decoded)
|
|
159
|
-
return jwt_decoded
|
{fastapi_factory_utilities-0.7.1.dist-info → fastapi_factory_utilities-0.8.3.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|