usso 0.28.0__py3-none-any.whl → 0.28.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.
- usso/auth/client.py +6 -4
- usso/integrations/fastapi/__init__.py +6 -1
- usso/integrations/fastapi/dependency.py +17 -32
- usso/integrations/fastapi/handler.py +16 -0
- {usso-0.28.0.dist-info → usso-0.28.1.dist-info}/METADATA +1 -1
- {usso-0.28.0.dist-info → usso-0.28.1.dist-info}/RECORD +10 -9
- {usso-0.28.0.dist-info → usso-0.28.1.dist-info}/WHEEL +0 -0
- {usso-0.28.0.dist-info → usso-0.28.1.dist-info}/entry_points.txt +0 -0
- {usso-0.28.0.dist-info → usso-0.28.1.dist-info}/licenses/LICENSE.txt +0 -0
- {usso-0.28.0.dist-info → usso-0.28.1.dist-info}/top_level.txt +0 -0
usso/auth/client.py
CHANGED
@@ -65,10 +65,12 @@ class UssoAuth:
|
|
65
65
|
except usso_jwt.exceptions.JWTError as e:
|
66
66
|
exp = e
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
_handle_exception(
|
69
|
+
"Unauthorized",
|
70
|
+
message=str(exp) if exp else None,
|
71
|
+
raise_exception=raise_exception,
|
72
|
+
**kwargs,
|
73
|
+
)
|
72
74
|
|
73
75
|
def user_data_from_api_key(self, api_key: str) -> UserData:
|
74
76
|
"""Get user data from an API key.
|
@@ -1,13 +1,10 @@
|
|
1
1
|
import logging
|
2
2
|
|
3
|
-
from starlette.status import HTTP_401_UNAUTHORIZED
|
4
|
-
|
5
3
|
from fastapi import Request, WebSocket
|
6
|
-
from fastapi.responses import JSONResponse
|
7
4
|
|
8
5
|
from ...auth import UssoAuth
|
9
6
|
from ...auth.config import AuthConfig, AvailableJwtConfigs
|
10
|
-
from ...exceptions import
|
7
|
+
from ...exceptions import _handle_exception
|
11
8
|
from ...models.user import UserData
|
12
9
|
from ...utils.method_utils import instance_method
|
13
10
|
|
@@ -26,6 +23,9 @@ class USSOAuthentication(UssoAuth):
|
|
26
23
|
super().__init__(jwt_config=jwt_config)
|
27
24
|
self.raise_exception = raise_exception
|
28
25
|
|
26
|
+
def __call__(self, request: Request) -> UserData:
|
27
|
+
return self.usso_access_security(request)
|
28
|
+
|
29
29
|
@instance_method
|
30
30
|
def get_request_jwt(self, request: Request | WebSocket) -> str | None:
|
31
31
|
for jwt_config in self.jwt_configs:
|
@@ -42,7 +42,7 @@ class USSOAuthentication(UssoAuth):
|
|
42
42
|
return token
|
43
43
|
return None
|
44
44
|
|
45
|
-
@instance_method
|
45
|
+
# @instance_method
|
46
46
|
def usso_access_security(self, request: Request) -> UserData | None:
|
47
47
|
"""Return the user associated with a token value."""
|
48
48
|
api_key = self.get_request_api_key(request)
|
@@ -54,15 +54,14 @@ class USSOAuthentication(UssoAuth):
|
|
54
54
|
return self.user_data_from_token(
|
55
55
|
token, raise_exception=self.raise_exception
|
56
56
|
)
|
57
|
-
if self.raise_exception:
|
58
|
-
raise USSOException(
|
59
|
-
status_code=HTTP_401_UNAUTHORIZED,
|
60
|
-
error="unauthorized",
|
61
|
-
message="No token provided",
|
62
|
-
)
|
63
|
-
return None
|
64
57
|
|
65
|
-
|
58
|
+
_handle_exception(
|
59
|
+
"Unauthorized",
|
60
|
+
message="No token provided",
|
61
|
+
raise_exception=self.raise_exception,
|
62
|
+
)
|
63
|
+
|
64
|
+
# @instance_method
|
66
65
|
def jwt_access_security_ws(self, websocket: WebSocket) -> UserData | None:
|
67
66
|
"""Return the user associated with a token value."""
|
68
67
|
api_key = self.get_request_api_key(websocket)
|
@@ -74,22 +73,8 @@ class USSOAuthentication(UssoAuth):
|
|
74
73
|
return self.user_data_from_token(
|
75
74
|
token, raise_exception=self.raise_exception
|
76
75
|
)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
)
|
83
|
-
return None
|
84
|
-
|
85
|
-
|
86
|
-
async def usso_exception_handler(request: Request, exc: USSOException):
|
87
|
-
return JSONResponse(
|
88
|
-
status_code=exc.status_code,
|
89
|
-
content={"message": exc.message, "error": exc.error},
|
90
|
-
)
|
91
|
-
|
92
|
-
|
93
|
-
EXCEPTION_HANDLERS = {
|
94
|
-
USSOException: usso_exception_handler,
|
95
|
-
}
|
76
|
+
_handle_exception(
|
77
|
+
"Unauthorized",
|
78
|
+
message="No token provided",
|
79
|
+
raise_exception=self.raise_exception,
|
80
|
+
)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from fastapi import Request
|
2
|
+
from fastapi.responses import JSONResponse
|
3
|
+
|
4
|
+
from ...exceptions import USSOException
|
5
|
+
|
6
|
+
|
7
|
+
async def usso_exception_handler(request: Request, exc: USSOException):
|
8
|
+
return JSONResponse(
|
9
|
+
status_code=exc.status_code,
|
10
|
+
content={"message": exc.message, "error": exc.error},
|
11
|
+
)
|
12
|
+
|
13
|
+
|
14
|
+
EXCEPTION_HANDLERS = {
|
15
|
+
USSOException: usso_exception_handler,
|
16
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: usso
|
3
|
-
Version: 0.28.
|
3
|
+
Version: 0.28.1
|
4
4
|
Summary: A plug-and-play client for integrating universal single sign-on (SSO) with Python frameworks, enabling secure and seamless authentication across microservices.
|
5
5
|
Author-email: Mahdi Kiani <mahdikiany@gmail.com>
|
6
6
|
Maintainer-email: Mahdi Kiani <mahdikiany@gmail.com>
|
@@ -2,12 +2,13 @@ usso/__init__.py,sha256=t3tYcw4qtGFpk7iakXTqEj5RlzIc8D2fs0I3FZcOmGs,571
|
|
2
2
|
usso/exceptions.py,sha256=cBzmMCwpNQKMjCUXO3bCcFwZJQQvbvJ5RxTH987ZlCI,1012
|
3
3
|
usso/auth/__init__.py,sha256=Dthv-iZTgsHTGcJrkJsnAtDCbRR5dNCx0Ut7MufoAXY,270
|
4
4
|
usso/auth/api_key.py,sha256=ec3q_mJtPiNb-eZt5MA4bantX1zRo3WwU2JfYBcGCGk,1254
|
5
|
-
usso/auth/client.py,sha256=
|
5
|
+
usso/auth/client.py,sha256=epxc0Lfyo_BBiL-w5parDayzSu-5B0c_VIDFAGoRdQc,2522
|
6
6
|
usso/auth/config.py,sha256=6tdnIg8iCrksuJGzpliw6QhRc8XsDUMR-dX0XY6QLHU,3833
|
7
7
|
usso/integrations/django/__init__.py,sha256=dKpbffHS5ouGtW6ooI2ivzjPmH_1rOBny85htR-KqrY,97
|
8
8
|
usso/integrations/django/middleware.py,sha256=8b-VYQ3FRhLnXSl4ZfHBpiA6VLY4b7b0-YoE_X41SFM,3443
|
9
|
-
usso/integrations/fastapi/__init__.py,sha256=
|
10
|
-
usso/integrations/fastapi/dependency.py,sha256=
|
9
|
+
usso/integrations/fastapi/__init__.py,sha256=ohToiqutHu3Okr8naunssDkamj1OdiG4OpPdBW0rt7U,204
|
10
|
+
usso/integrations/fastapi/dependency.py,sha256=9CaRSvCNbrSQr7EQd6SEs7HhxULWvXLkEX89L5rsnZc,2543
|
11
|
+
usso/integrations/fastapi/handler.py,sha256=MNDoBYdySumFsBgVw-xir3jXXH63KehFXKCh-pNnNZQ,386
|
11
12
|
usso/models/user.py,sha256=jG8jlt6F2pHHgqnsRRP6kCuRNK-aO9FE5Mt7iiuPPnU,3293
|
12
13
|
usso/session/__init__.py,sha256=tE4qWUdSI7iN_pywm47Mg8NKOTBa2nCNwCy3wCZWRmU,124
|
13
14
|
usso/session/async_session.py,sha256=7OKvFnJQaHnLjeQKSW6bltl0KcQGzOvUje-bJKbxFZY,3692
|
@@ -16,9 +17,9 @@ usso/session/session.py,sha256=B29Srxoq7webDvmfmfTeeh5JjtLSHvJijM2WCEZOh-8,1506
|
|
16
17
|
usso/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
18
|
usso/utils/method_utils.py,sha256=1NMN4le04PWXDSJZK-nf7q2IFqOMkwYcCnslFXAzlH8,355
|
18
19
|
usso/utils/string_utils.py,sha256=7tziAa2Cwa7xhwM_NF4DSY3BHoqVaWgJ21VuV8LvhrY,253
|
19
|
-
usso-0.28.
|
20
|
-
usso-0.28.
|
21
|
-
usso-0.28.
|
22
|
-
usso-0.28.
|
23
|
-
usso-0.28.
|
24
|
-
usso-0.28.
|
20
|
+
usso-0.28.1.dist-info/licenses/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
|
21
|
+
usso-0.28.1.dist-info/METADATA,sha256=z1_LTJnbQtGrgMq3nSofRnGLpPv3lnKMpez9sLagqaY,4845
|
22
|
+
usso-0.28.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
23
|
+
usso-0.28.1.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
|
24
|
+
usso-0.28.1.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
|
25
|
+
usso-0.28.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|