usso 0.22.0__py3-none-any.whl → 0.23.0__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 +49 -0
- {usso-0.22.0.dist-info → usso-0.23.0.dist-info}/METADATA +1 -1
- {usso-0.22.0.dist-info → usso-0.23.0.dist-info}/RECORD +7 -6
- {usso-0.22.0.dist-info → usso-0.23.0.dist-info}/WHEEL +1 -1
- {usso-0.22.0.dist-info → usso-0.23.0.dist-info}/LICENSE.txt +0 -0
- {usso-0.22.0.dist-info → usso-0.23.0.dist-info}/entry_points.txt +0 -0
- {usso-0.22.0.dist-info → usso-0.23.0.dist-info}/top_level.txt +0 -0
usso/async_session.py
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
from datetime import datetime
|
2
|
+
import jwt
|
3
|
+
import aiohttp
|
4
|
+
import asyncio
|
5
|
+
|
6
|
+
|
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)
|
12
|
+
self.sso_refresh_url = sso_refresh_url
|
13
|
+
self.refresh_token = refresh_token
|
14
|
+
self.access_token = None
|
15
|
+
|
16
|
+
async def _refresh(self):
|
17
|
+
if not self.refresh_token:
|
18
|
+
raise ValueError("Refresh token not provided or invalid.")
|
19
|
+
|
20
|
+
async with aiohttp.ClientSession() as session:
|
21
|
+
async with session.post(
|
22
|
+
self.sso_refresh_url,
|
23
|
+
json={"refresh_token": self.refresh_token},
|
24
|
+
) as response:
|
25
|
+
response.raise_for_status()
|
26
|
+
return await response.json()
|
27
|
+
|
28
|
+
async def _ensure_valid_token(self):
|
29
|
+
if self.access_token:
|
30
|
+
decoded_token = jwt.decode(
|
31
|
+
self.access_token, options={"verify_signature": False}
|
32
|
+
)
|
33
|
+
exp = datetime.fromtimestamp(decoded_token.get("exp"))
|
34
|
+
if exp < datetime.now():
|
35
|
+
self.access_token = None
|
36
|
+
|
37
|
+
if not self.access_token:
|
38
|
+
token_data = await self._refresh()
|
39
|
+
self.access_token = token_data["access_token"]
|
40
|
+
|
41
|
+
self.headers.update({"Authorization": f"Bearer {self.access_token}"})
|
42
|
+
|
43
|
+
async def __aenter__(self):
|
44
|
+
await self._ensure_valid_token()
|
45
|
+
return self
|
46
|
+
|
47
|
+
async def __aexit__(self, exc_type, exc_value, traceback):
|
48
|
+
await self.close()
|
49
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: usso
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.23.0
|
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,6 +1,7 @@
|
|
1
1
|
usso/__init__.py,sha256=RN0E6HI9kHedvDxheDPVWiAmh-169IrhXfvq_sHphQc,65
|
2
2
|
usso/api.py,sha256=MnUg-DcrmMXW1CxEcRlJQhIYl5J1WKvjqHQOz7jsrwE,5137
|
3
3
|
usso/async_api.py,sha256=aXgYKMT1h4HV8szCqMCnoMmDya-IO6mVROpK8cSB5O4,5582
|
4
|
+
usso/async_session.py,sha256=zFqK2H5QGijrHWybR_IWLtgdtcWeR9PUtCRsqzKMLWw,1578
|
4
5
|
usso/b64tools.py,sha256=7lsz_Rn6PITkKWfjcebmewdhvFs2A7H4t_WE33MgZ0Y,626
|
5
6
|
usso/core.py,sha256=bJPKxJLcYe5zWoiNM_n9ajHSP5bARN8u9tsRQ6fLnyA,3998
|
6
7
|
usso/exceptions.py,sha256=hawOAuVbvQtjgRfwp1KFZ4SmV7fh720y5Gom9JVA8W8,504
|
@@ -8,9 +9,9 @@ usso/package_data.dat,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
9
|
usso/session.py,sha256=S3dFXzar0Pcwxj5TGqadKwGdmzmzgp4H2W3brfOwJ6A,1184
|
9
10
|
usso/fastapi/__init__.py,sha256=TRTDVJo8bwZQDAuCQFhh-g1XbIspf6TdFYXGAO5cgAU,130
|
10
11
|
usso/fastapi/integration.py,sha256=-zW3dwyvnVx59DgtV8JKL6YwG_ksFY2dOMwZAtwmEmY,1816
|
11
|
-
usso-0.
|
12
|
-
usso-0.
|
13
|
-
usso-0.
|
14
|
-
usso-0.
|
15
|
-
usso-0.
|
16
|
-
usso-0.
|
12
|
+
usso-0.23.0.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
|
13
|
+
usso-0.23.0.dist-info/METADATA,sha256=8V-92GyH9HNte3lTORWyH8G2TmVhbK9ksP5LpRcrmzM,4234
|
14
|
+
usso-0.23.0.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
|
15
|
+
usso-0.23.0.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
|
16
|
+
usso-0.23.0.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
|
17
|
+
usso-0.23.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|