usso 0.27.8__py3-none-any.whl → 0.27.9__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/session/async_session.py +44 -17
- usso/session/session.py +1 -0
- {usso-0.27.8.dist-info → usso-0.27.9.dist-info}/METADATA +1 -1
- {usso-0.27.8.dist-info → usso-0.27.9.dist-info}/RECORD +8 -8
- {usso-0.27.8.dist-info → usso-0.27.9.dist-info}/LICENSE.txt +0 -0
- {usso-0.27.8.dist-info → usso-0.27.9.dist-info}/WHEEL +0 -0
- {usso-0.27.8.dist-info → usso-0.27.9.dist-info}/entry_points.txt +0 -0
- {usso-0.27.8.dist-info → usso-0.27.9.dist-info}/top_level.txt +0 -0
usso/session/async_session.py
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
import os
|
2
|
-
|
3
2
|
import httpx
|
4
|
-
|
5
3
|
from ..core import is_expired
|
6
4
|
from .base_session import BaseUssoSession
|
7
5
|
|
8
6
|
|
9
7
|
class AsyncUssoSession(httpx.AsyncClient, BaseUssoSession):
|
10
|
-
|
11
8
|
def __init__(
|
12
9
|
self,
|
13
10
|
*,
|
@@ -28,33 +25,63 @@ class AsyncUssoSession(httpx.AsyncClient, BaseUssoSession):
|
|
28
25
|
usso_api_key=usso_api_key,
|
29
26
|
user_id=user_id,
|
30
27
|
)
|
28
|
+
self._refresh_sync()
|
31
29
|
|
32
|
-
|
30
|
+
def _prepare_refresh_request(self) -> tuple[dict, dict]:
|
31
|
+
"""
|
32
|
+
Helper function to prepare headers and parameters for refresh requests.
|
33
|
+
"""
|
34
|
+
headers = {"x-api-key": self.usso_api_key} if self.usso_api_key else {}
|
33
35
|
params = {"user_id": self.user_id} if self.user_id else {}
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
return headers, params
|
37
|
+
|
38
|
+
def _handle_refresh_response(self, response: httpx.Response) -> dict:
|
39
|
+
"""
|
40
|
+
Helper function to process the response from refresh requests.
|
41
|
+
"""
|
39
42
|
response.raise_for_status()
|
40
|
-
data
|
43
|
+
data = response.json()
|
44
|
+
self.access_token = data.get("access_token")
|
41
45
|
self._refresh_token = data.get("token", {}).get("refresh_token")
|
46
|
+
if self.access_token:
|
47
|
+
self.headers.update({"Authorization": f"Bearer {self.access_token}"})
|
48
|
+
return data
|
49
|
+
|
50
|
+
def _refresh_sync(self) -> dict:
|
51
|
+
assert (
|
52
|
+
self.refresh_token or self.usso_api_key
|
53
|
+
), "refresh_token or usso_api_key is required"
|
54
|
+
|
55
|
+
headers, params = self._prepare_refresh_request()
|
56
|
+
|
57
|
+
if self.usso_api_key and not self.refresh_token:
|
58
|
+
response = httpx.get(
|
59
|
+
f"{self.usso_refresh_url}/api", headers=headers, params=params
|
60
|
+
)
|
61
|
+
self._handle_refresh_response(response)
|
42
62
|
|
43
|
-
|
63
|
+
response = httpx.post(
|
64
|
+
self.usso_refresh_url, json={"refresh_token": self.refresh_token}
|
65
|
+
)
|
66
|
+
return self._handle_refresh_response(response)
|
67
|
+
|
68
|
+
async def _refresh(self) -> dict:
|
44
69
|
assert (
|
45
70
|
self.refresh_token or self.usso_api_key
|
46
71
|
), "refresh_token or usso_api_key is required"
|
47
72
|
|
73
|
+
headers, params = self._prepare_refresh_request()
|
74
|
+
|
48
75
|
if self.usso_api_key and not self.refresh_token:
|
49
|
-
await self.
|
76
|
+
response = await self.get(
|
77
|
+
f"{self.usso_refresh_url}/api", headers=headers, params=params
|
78
|
+
)
|
79
|
+
self._handle_refresh_response(response)
|
50
80
|
|
51
81
|
response = await self.post(
|
52
|
-
self.usso_refresh_url, json={"refresh_token":
|
82
|
+
self.usso_refresh_url, json={"refresh_token": self.refresh_token}
|
53
83
|
)
|
54
|
-
|
55
|
-
self.access_token = response.json().get("access_token")
|
56
|
-
self.headers.update({"Authorization": f"Bearer {self.access_token}"})
|
57
|
-
return response.json()
|
84
|
+
return self._handle_refresh_response(response)
|
58
85
|
|
59
86
|
async def get_session(self):
|
60
87
|
if self.api_key:
|
usso/session/session.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: usso
|
3
|
-
Version: 0.27.
|
3
|
+
Version: 0.27.9
|
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>
|
@@ -11,12 +11,12 @@ usso/django/middleware.py,sha256=EEEpHvMQ6QiWw2HY8zQ2Aec0RCATcLWsCKeyiPWJKio,324
|
|
11
11
|
usso/fastapi/__init__.py,sha256=0EcdOzb4f3yu9nILIdGWnlyUz-0VaVX2az1e3f2BusI,201
|
12
12
|
usso/fastapi/integration.py,sha256=IonxxNj_B9sG2j672rIzE047qo972vk7ch4-eGENp3Q,2638
|
13
13
|
usso/session/__init__.py,sha256=tE4qWUdSI7iN_pywm47Mg8NKOTBa2nCNwCy3wCZWRmU,124
|
14
|
-
usso/session/async_session.py,sha256=
|
14
|
+
usso/session/async_session.py,sha256=yOWePytbrPrN489xLGFm3jz-dW0I_esRrnGoDwXcKx0,3412
|
15
15
|
usso/session/base_session.py,sha256=1A12QulP6UHe1lqYEihGAcBaZ_7C09EWZt3fB6JvbOE,2347
|
16
|
-
usso/session/session.py,sha256=
|
17
|
-
usso-0.27.
|
18
|
-
usso-0.27.
|
19
|
-
usso-0.27.
|
20
|
-
usso-0.27.
|
21
|
-
usso-0.27.
|
22
|
-
usso-0.27.
|
16
|
+
usso/session/session.py,sha256=us23VzndGIyBW1TbtfL_qwmMobG9ciGuoDlsgraJUkQ,2357
|
17
|
+
usso-0.27.9.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
|
18
|
+
usso-0.27.9.dist-info/METADATA,sha256=u_q1K9l6YiNxatNEWwp_WzIW0UoeWSxYxjYHTFh9QeE,4528
|
19
|
+
usso-0.27.9.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
20
|
+
usso-0.27.9.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
|
21
|
+
usso-0.27.9.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
|
22
|
+
usso-0.27.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|