usso 0.24.6__py3-none-any.whl → 0.24.7__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/async_session.py CHANGED
@@ -1,17 +1,14 @@
1
1
  from datetime import datetime
2
-
3
2
  import aiohttp
4
3
  import jwt
5
4
 
6
5
 
7
- class AsyncUssoSession(aiohttp.ClientSession):
8
- def __init__(
9
- self, sso_refresh_url: str, refresh_token: str | None = None, **kwargs
10
- ):
11
- super().__init__(**kwargs)
6
+ class AsyncUssoSession:
7
+ def __init__(self, sso_refresh_url: str, refresh_token: str | None = None):
12
8
  self.sso_refresh_url = sso_refresh_url
13
9
  self.refresh_token = refresh_token
14
10
  self.access_token = None
11
+ self.session = None # This will hold the aiohttp session
15
12
 
16
13
  async def _refresh(self):
17
14
  if not self.refresh_token:
@@ -30,19 +27,27 @@ class AsyncUssoSession(aiohttp.ClientSession):
30
27
  decoded_token = jwt.decode(
31
28
  self.access_token, options={"verify_signature": False}
32
29
  )
33
- exp = datetime.fromtimestamp(decoded_token.get("exp"))
34
- if exp < datetime.now():
35
- self.access_token = None
30
+ exp = decoded_token.get("exp")
31
+
32
+ if exp and datetime.fromtimestamp(exp) < datetime.now():
33
+ self.access_token = None # Token expired, need a new one
36
34
 
37
35
  if not self.access_token:
36
+ # Get a new token if none exists or it has expired
38
37
  token_data = await self._refresh()
39
38
  self.access_token = token_data["access_token"]
40
39
 
41
- self.headers.update({"Authorization": f"Bearer {self.access_token}"})
40
+ # Update headers with the new access token
41
+ if self.session:
42
+ self.session.headers.update(
43
+ {"Authorization": f"Bearer {self.access_token}"}
44
+ )
42
45
 
43
46
  async def __aenter__(self):
44
- await self._ensure_valid_token()
47
+ self.session = aiohttp.ClientSession() # Initialize the session
48
+ await self._ensure_valid_token() # Ensure valid token before usage
45
49
  return self
46
50
 
47
51
  async def __aexit__(self, exc_type, exc_value, traceback):
48
- await self.close()
52
+ if self.session:
53
+ await self.session.close() # Close the session properly
usso/fastapi/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
1
  from .integration import (
2
2
  jwt_access_security,
3
- jwt_access_security_ws,
4
3
  jwt_access_security_None,
4
+ jwt_access_security_ws,
5
5
  )
6
6
 
7
7
  __all__ = ["jwt_access_security", "jwt_access_security_ws", "jwt_access_security_None"]
@@ -12,7 +12,7 @@ logger = logging.getLogger("usso")
12
12
  def get_request_token(request: Request | WebSocket) -> UserData | None:
13
13
  authorization = request.headers.get("Authorization")
14
14
  token = None
15
-
15
+
16
16
  if authorization:
17
17
  scheme, credentials = Usso().get_authorization_scheme_param(authorization)
18
18
  if scheme.lower() == "bearer":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: usso
3
- Version: 0.24.6
3
+ Version: 0.24.7
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>
@@ -1,7 +1,7 @@
1
1
  usso/__init__.py,sha256=NnOS_S1a-JKTOlGe1nw-kCL3m0y82mA2mDraus7BQ2o,120
2
2
  usso/api.py,sha256=xlDq2nZNpq3mhAvqIbGEfANHNjJpPquSeULBfS7iMJw,5094
3
3
  usso/async_api.py,sha256=rb-Xh5oudmZrPYM_iH_B75b5Z0Fvi1V1uurdcKE51w0,5551
4
- usso/async_session.py,sha256=78MxGFojmqYmTe2iytrhPNrfYdvEn24tVJEiRJVeoyk,1563
4
+ usso/async_session.py,sha256=AClLpmM0q-P_ES_iMfv8CDUdyZtKb4FA-VSp5Uh4esw,1960
5
5
  usso/b64tools.py,sha256=HGQ0E59vzjrQo2-4jrcY03ebtTaYwTtCZ7KgJaEmxO0,610
6
6
  usso/core.py,sha256=m6Y-g70FuPYZM3AMtsEVVToQkYrf4WwNVH8C4HZRzl8,4103
7
7
  usso/exceptions.py,sha256=hawOAuVbvQtjgRfwp1KFZ4SmV7fh720y5Gom9JVA8W8,504
@@ -9,11 +9,11 @@ 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
11
  usso/django/middleware.py,sha256=EEEpHvMQ6QiWw2HY8zQ2Aec0RCATcLWsCKeyiPWJKio,3245
12
- usso/fastapi/__init__.py,sha256=kmjbCK-V01myG3ElJv0nRcYJt3lMtd262Q0uXIRC6ys,201
13
- usso/fastapi/integration.py,sha256=qu2HBsm4hPzM-fctO5rGZAHH2Lo8fk5U0K1jcEGDt2U,1673
14
- usso-0.24.6.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
15
- usso-0.24.6.dist-info/METADATA,sha256=GuPLk_R-UuuooiBQl3Fkj9BhxDP9URepdzvEAbLQojc,4231
16
- usso-0.24.6.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
17
- usso-0.24.6.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
18
- usso-0.24.6.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
19
- usso-0.24.6.dist-info/RECORD,,
12
+ usso/fastapi/__init__.py,sha256=0EcdOzb4f3yu9nILIdGWnlyUz-0VaVX2az1e3f2BusI,201
13
+ usso/fastapi/integration.py,sha256=VAUWaa7ChQ1jTtn8A136VgyG6t2kDo5pGK-3RgmNDVs,1669
14
+ usso-0.24.7.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
15
+ usso-0.24.7.dist-info/METADATA,sha256=Q_WAGLUFZp3qPM7ZfK2J2gYaZ4Ugvd0TayQr2L4C5j8,4231
16
+ usso-0.24.7.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
17
+ usso-0.24.7.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
18
+ usso-0.24.7.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
19
+ usso-0.24.7.dist-info/RECORD,,
File without changes