usso 0.24.2__py3-none-any.whl → 0.24.4__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 CHANGED
@@ -19,18 +19,14 @@ 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
- logger.debug("Processing request in USSO authentication middleware")
23
-
24
- # Extract and verify JWT from Authorization header or cookies
25
- user_data = self.jwt_access_security(request)
22
+ if hasattr(request, "user") and 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 None
29
+ request._dont_enforce_csrf_checks = True
34
30
  except USSOException as e:
35
31
  # Handle any errors raised by USSO authentication
36
32
  return JsonResponse({"error": str(e)}, status=401)
@@ -46,6 +42,15 @@ class USSOAuthenticationMiddleware(MiddlewareMixin):
46
42
 
47
43
  return request.COOKIES.get("usso_access_token")
48
44
 
45
+ def jwt_access_security_none(self, request: HttpRequest) -> UserData | None:
46
+ """Return the user associated with a token value."""
47
+ token = self.get_request_token(request)
48
+ if not token:
49
+ return None
50
+ return Usso(jwks_url=settings.USSO_JWK_URL).user_data_from_token(
51
+ token, raise_exception=False
52
+ )
53
+
49
54
  def jwt_access_security(self, request: HttpRequest) -> UserData | None:
50
55
  """Return the user associated with a token value."""
51
56
  token = self.get_request_token(request)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: usso
3
- Version: 0.24.2
3
+ Version: 0.24.4
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=GXorowWoPXRqFNp6KkXjd5NXszik-pUFR_cECz8E2As,3040
11
+ usso/django/middleware.py,sha256=EEEpHvMQ6QiWw2HY8zQ2Aec0RCATcLWsCKeyiPWJKio,3245
12
12
  usso/fastapi/__init__.py,sha256=TRTDVJo8bwZQDAuCQFhh-g1XbIspf6TdFYXGAO5cgAU,130
13
13
  usso/fastapi/integration.py,sha256=Lt3qRwQ59K7GCDHgB0dE0hpc18gYZEjwMb_xS4qsGg0,1651
14
- usso-0.24.2.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
15
- usso-0.24.2.dist-info/METADATA,sha256=6VZqL6bLF1h4muBRx2HZZcab4RZSiPbJQ5yjKmns_0U,4231
16
- usso-0.24.2.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
17
- usso-0.24.2.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
18
- usso-0.24.2.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
19
- usso-0.24.2.dist-info/RECORD,,
14
+ usso-0.24.4.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
15
+ usso-0.24.4.dist-info/METADATA,sha256=cUhJmktVNYhlVXcUQO13nAipxE0367c72bL0sxVMW4s,4231
16
+ usso-0.24.4.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
17
+ usso-0.24.4.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
18
+ usso-0.24.4.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
19
+ usso-0.24.4.dist-info/RECORD,,
File without changes