usso 0.24.1__py3-none-any.whl → 0.24.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.
- usso/django/middleware.py +12 -11
- {usso-0.24.1.dist-info → usso-0.24.3.dist-info}/METADATA +1 -1
- {usso-0.24.1.dist-info → usso-0.24.3.dist-info}/RECORD +7 -7
- {usso-0.24.1.dist-info → usso-0.24.3.dist-info}/LICENSE.txt +0 -0
- {usso-0.24.1.dist-info → usso-0.24.3.dist-info}/WHEEL +0 -0
- {usso-0.24.1.dist-info → usso-0.24.3.dist-info}/entry_points.txt +0 -0
- {usso-0.24.1.dist-info → usso-0.24.3.dist-info}/top_level.txt +0 -0
usso/django/middleware.py
CHANGED
@@ -19,21 +19,13 @@ class USSOAuthenticationMiddleware(MiddlewareMixin):
|
|
19
19
|
Middleware to authenticate users by JWT token and create or return a user in the database.
|
20
20
|
"""
|
21
21
|
try:
|
22
|
-
|
23
|
-
|
24
|
-
# Extract and verify JWT from Authorization header or cookies
|
25
|
-
user_data = self.jwt_access_security(request)
|
22
|
+
if request.user.is_authenticated:
|
23
|
+
return
|
26
24
|
|
25
|
+
user_data = self.jwt_access_security_none(request)
|
27
26
|
if user_data:
|
28
|
-
# Check database for the user or create a new one
|
29
27
|
user = self.get_or_create_user(user_data)
|
30
|
-
# Attach the user to the request
|
31
28
|
request.user = user
|
32
|
-
else:
|
33
|
-
return JsonResponse(
|
34
|
-
{"error": "Authentication failed: No valid JWT token provided."},
|
35
|
-
status=401,
|
36
|
-
)
|
37
29
|
except USSOException as e:
|
38
30
|
# Handle any errors raised by USSO authentication
|
39
31
|
return JsonResponse({"error": str(e)}, status=401)
|
@@ -49,6 +41,15 @@ class USSOAuthenticationMiddleware(MiddlewareMixin):
|
|
49
41
|
|
50
42
|
return request.COOKIES.get("usso_access_token")
|
51
43
|
|
44
|
+
def jwt_access_security_none(self, request: HttpRequest) -> UserData | None:
|
45
|
+
"""Return the user associated with a token value."""
|
46
|
+
token = self.get_request_token(request)
|
47
|
+
if not token:
|
48
|
+
return None
|
49
|
+
return Usso(jwks_url=settings.USSO_JWK_URL).user_data_from_token(
|
50
|
+
token, raise_exception=False
|
51
|
+
)
|
52
|
+
|
52
53
|
def jwt_access_security(self, request: HttpRequest) -> UserData | None:
|
53
54
|
"""Return the user associated with a token value."""
|
54
55
|
token = self.get_request_token(request)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: usso
|
3
|
-
Version: 0.24.
|
3
|
+
Version: 0.24.3
|
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>
|
@@ -8,12 +8,12 @@ usso/exceptions.py,sha256=hawOAuVbvQtjgRfwp1KFZ4SmV7fh720y5Gom9JVA8W8,504
|
|
8
8
|
usso/package_data.dat,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
9
|
usso/session.py,sha256=S3dFXzar0Pcwxj5TGqadKwGdmzmzgp4H2W3brfOwJ6A,1184
|
10
10
|
usso/django/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
usso/django/middleware.py,sha256=
|
11
|
+
usso/django/middleware.py,sha256=gmLPbbcoMQqoqOl3InZwOhlUfI13MrPf2B6fCJrbeHw,3159
|
12
12
|
usso/fastapi/__init__.py,sha256=TRTDVJo8bwZQDAuCQFhh-g1XbIspf6TdFYXGAO5cgAU,130
|
13
13
|
usso/fastapi/integration.py,sha256=Lt3qRwQ59K7GCDHgB0dE0hpc18gYZEjwMb_xS4qsGg0,1651
|
14
|
-
usso-0.24.
|
15
|
-
usso-0.24.
|
16
|
-
usso-0.24.
|
17
|
-
usso-0.24.
|
18
|
-
usso-0.24.
|
19
|
-
usso-0.24.
|
14
|
+
usso-0.24.3.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
|
15
|
+
usso-0.24.3.dist-info/METADATA,sha256=MfFSi6Bn3qxmUo-LDUJZHGIgCGWqaTDvLqvber8I5hc,4231
|
16
|
+
usso-0.24.3.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
17
|
+
usso-0.24.3.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
|
18
|
+
usso-0.24.3.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
|
19
|
+
usso-0.24.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|