usso 0.27.2__tar.gz → 0.27.4__tar.gz
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-0.27.2/src/usso.egg-info → usso-0.27.4}/PKG-INFO +9 -3
- {usso-0.27.2 → usso-0.27.4}/README.md +8 -2
- {usso-0.27.2 → usso-0.27.4}/pyproject.toml +1 -1
- {usso-0.27.2 → usso-0.27.4}/src/usso/session/async_session.py +17 -13
- usso-0.27.2/src/usso/session/session.py → usso-0.27.4/src/usso/session/base_session.py +10 -57
- usso-0.27.4/src/usso/session/session.py +71 -0
- {usso-0.27.2 → usso-0.27.4/src/usso.egg-info}/PKG-INFO +9 -3
- {usso-0.27.2 → usso-0.27.4}/src/usso.egg-info/SOURCES.txt +1 -0
- {usso-0.27.2 → usso-0.27.4}/LICENSE.txt +0 -0
- {usso-0.27.2 → usso-0.27.4}/setup.cfg +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/__init__.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/b64tools.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/client/__init__.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/client/api.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/client/async_api.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/core.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/django/__init__.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/django/middleware.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/exceptions.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/fastapi/__init__.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/fastapi/integration.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/schemas.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso/session/__init__.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso.egg-info/dependency_links.txt +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso.egg-info/entry_points.txt +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso.egg-info/requires.txt +0 -0
- {usso-0.27.2 → usso-0.27.4}/src/usso.egg-info/top_level.txt +0 -0
- {usso-0.27.2 → usso-0.27.4}/tests/test_api.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/tests/test_core.py +0 -0
- {usso-0.27.2 → usso-0.27.4}/tests/test_simple.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: usso
|
3
|
-
Version: 0.27.
|
3
|
+
Version: 0.27.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>
|
@@ -81,7 +81,7 @@ The USSO-Client provides a universal single sign-on (SSO) integration for micros
|
|
81
81
|
Install the USSO client using pip:
|
82
82
|
|
83
83
|
```bash
|
84
|
-
pip install usso
|
84
|
+
pip install usso
|
85
85
|
```
|
86
86
|
|
87
87
|
To add framework-specific support, use the following commands:
|
@@ -89,7 +89,13 @@ To add framework-specific support, use the following commands:
|
|
89
89
|
For FastAPI:
|
90
90
|
|
91
91
|
```bash
|
92
|
-
pip install "usso
|
92
|
+
pip install "usso[fastapi]"
|
93
|
+
```
|
94
|
+
|
95
|
+
For Django:
|
96
|
+
|
97
|
+
```bash
|
98
|
+
pip install "usso[django]"
|
93
99
|
```
|
94
100
|
|
95
101
|
## Quick Start
|
@@ -14,7 +14,7 @@ The USSO-Client provides a universal single sign-on (SSO) integration for micros
|
|
14
14
|
Install the USSO client using pip:
|
15
15
|
|
16
16
|
```bash
|
17
|
-
pip install usso
|
17
|
+
pip install usso
|
18
18
|
```
|
19
19
|
|
20
20
|
To add framework-specific support, use the following commands:
|
@@ -22,7 +22,13 @@ To add framework-specific support, use the following commands:
|
|
22
22
|
For FastAPI:
|
23
23
|
|
24
24
|
```bash
|
25
|
-
pip install "usso
|
25
|
+
pip install "usso[fastapi]"
|
26
|
+
```
|
27
|
+
|
28
|
+
For Django:
|
29
|
+
|
30
|
+
```bash
|
31
|
+
pip install "usso[django]"
|
26
32
|
```
|
27
33
|
|
28
34
|
## Quick Start
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "usso"
|
7
|
-
version = "0.27.
|
7
|
+
version = "0.27.4"
|
8
8
|
description = "A plug-and-play client for integrating universal single sign-on (SSO) with Python frameworks, enabling secure and seamless authentication across microservices."
|
9
9
|
readme = "README.md"
|
10
10
|
requires-python = ">=3.9"
|
@@ -1,29 +1,33 @@
|
|
1
|
+
import os
|
2
|
+
|
1
3
|
import httpx
|
2
4
|
|
3
5
|
from ..core import is_expired
|
4
|
-
from .
|
6
|
+
from .base_session import BaseUssoSession
|
5
7
|
|
6
8
|
|
7
9
|
class AsyncUssoSession(httpx.AsyncClient, BaseUssoSession):
|
10
|
+
|
8
11
|
def __init__(
|
9
12
|
self,
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
*,
|
14
|
+
usso_base_url: str | None = os.getenv("USSO_URL"),
|
15
|
+
api_key: str | None = os.getenv("USSO_API_KEY"),
|
16
|
+
usso_refresh_url: str | None = os.getenv("USSO_REFRESH_URL"),
|
17
|
+
refresh_token: str | None = os.getenv("USSO_REFRESH_TOKEN"),
|
18
|
+
usso_api_key: str | None = os.getenv("USSO_ADMIN_API_KEY"),
|
15
19
|
user_id: str | None = None,
|
16
20
|
):
|
21
|
+
httpx.AsyncClient.__init__(self)
|
17
22
|
BaseUssoSession.__init__(
|
18
23
|
self,
|
19
|
-
usso_base_url,
|
20
|
-
api_key,
|
21
|
-
usso_refresh_url,
|
22
|
-
refresh_token,
|
23
|
-
usso_api_key,
|
24
|
-
user_id,
|
24
|
+
usso_base_url=usso_base_url,
|
25
|
+
api_key=api_key,
|
26
|
+
usso_refresh_url=usso_refresh_url,
|
27
|
+
refresh_token=refresh_token,
|
28
|
+
usso_api_key=usso_api_key,
|
29
|
+
user_id=user_id,
|
25
30
|
)
|
26
|
-
httpx.AsyncClient.__init__(self, headers=self.headers)
|
27
31
|
|
28
32
|
async def _refresh_api(self):
|
29
33
|
params = {"user_id": self.user_id} if self.user_id else {}
|
@@ -1,18 +1,17 @@
|
|
1
|
+
import os
|
1
2
|
from urllib.parse import urlparse
|
2
|
-
|
3
|
-
import requests
|
4
|
-
|
5
|
-
from ..core import is_expired
|
3
|
+
from usso.core import is_expired
|
6
4
|
|
7
5
|
|
8
6
|
class BaseUssoSession:
|
7
|
+
|
9
8
|
def __init__(
|
10
9
|
self,
|
11
|
-
usso_base_url: str | None =
|
12
|
-
api_key: str | None =
|
13
|
-
usso_refresh_url: str | None =
|
14
|
-
refresh_token: str | None =
|
15
|
-
usso_api_key: str | None =
|
10
|
+
usso_base_url: str | None = os.getenv("USSO_URL"),
|
11
|
+
api_key: str | None = os.getenv("USSO_API_KEY"),
|
12
|
+
usso_refresh_url: str | None = os.getenv("USSO_REFRESH_URL"),
|
13
|
+
refresh_token: str | None = os.getenv("USSO_REFRESH_TOKEN"),
|
14
|
+
usso_api_key: str | None = os.getenv("USSO_ADMIN_API_KEY"),
|
16
15
|
user_id: str | None = None,
|
17
16
|
):
|
18
17
|
assert (
|
@@ -30,15 +29,13 @@ class BaseUssoSession:
|
|
30
29
|
|
31
30
|
self.usso_refresh_url = usso_refresh_url or f"{usso_base_url}/auth/refresh"
|
32
31
|
self._refresh_token = refresh_token
|
33
|
-
self.session = requests.Session()
|
34
32
|
self.access_token = None
|
35
33
|
self.api_key = api_key
|
36
34
|
self.usso_api_key = usso_api_key
|
37
35
|
self.user_id = user_id
|
38
|
-
self.headers = {}
|
36
|
+
self.headers = getattr(self, "headers", {})
|
39
37
|
if api_key:
|
40
|
-
self.headers
|
41
|
-
self.session.headers.update(self.headers)
|
38
|
+
self.headers.update({"x-api-key": api_key})
|
42
39
|
|
43
40
|
@property
|
44
41
|
def refresh_token(self):
|
@@ -70,47 +67,3 @@ class BaseUssoSession:
|
|
70
67
|
|
71
68
|
def options(self, url: str, **kwargs):
|
72
69
|
return self._request("OPTIONS", url, **kwargs)
|
73
|
-
|
74
|
-
|
75
|
-
class UssoSession(BaseUssoSession):
|
76
|
-
def _refresh_api(self):
|
77
|
-
params = {"user_id": self.user_id} if self.user_id else {}
|
78
|
-
response = requests.get(
|
79
|
-
f"{self.usso_refresh_url}/api",
|
80
|
-
headers={"x-api-key": self.usso_api_key},
|
81
|
-
params=params,
|
82
|
-
)
|
83
|
-
response.raise_for_status()
|
84
|
-
data: dict = response.json()
|
85
|
-
self._refresh_token = data.get("token", {}).get("refresh_token")
|
86
|
-
|
87
|
-
def _refresh(self):
|
88
|
-
assert (
|
89
|
-
self.refresh_token or self.usso_api_key
|
90
|
-
), "refresh_token or usso_api_key is required"
|
91
|
-
|
92
|
-
if self.usso_api_key and not self.refresh_token:
|
93
|
-
self._refresh_api()
|
94
|
-
|
95
|
-
response = requests.post(
|
96
|
-
self.usso_refresh_url, json={"refresh_token": f"{self.refresh_token}"}
|
97
|
-
)
|
98
|
-
response.raise_for_status()
|
99
|
-
self.access_token = response.json().get("access_token")
|
100
|
-
self.session.headers.update({"Authorization": f"Bearer {self.access_token}"})
|
101
|
-
return response.json()
|
102
|
-
|
103
|
-
def get_session(self):
|
104
|
-
if self.api_key:
|
105
|
-
return self.session
|
106
|
-
|
107
|
-
if not self.access_token or is_expired(self.access_token):
|
108
|
-
self._refresh()
|
109
|
-
return self.session
|
110
|
-
|
111
|
-
def _request(self, method: str, url: str, **kwargs):
|
112
|
-
session = self.get_session()
|
113
|
-
return session.request(method, url, **kwargs)
|
114
|
-
|
115
|
-
def close(self):
|
116
|
-
self.session.close()
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
import requests
|
4
|
+
from usso.core import is_expired
|
5
|
+
|
6
|
+
from .base_session import BaseUssoSession
|
7
|
+
|
8
|
+
|
9
|
+
class UssoSession(BaseUssoSession, requests.Session):
|
10
|
+
|
11
|
+
def __init__(
|
12
|
+
self,
|
13
|
+
*,
|
14
|
+
usso_base_url: str | None = os.getenv("USSO_URL"),
|
15
|
+
api_key: str | None = os.getenv("USSO_API_KEY"),
|
16
|
+
usso_refresh_url: str | None = os.getenv("USSO_REFRESH_URL"),
|
17
|
+
refresh_token: str | None = os.getenv("USSO_REFRESH_TOKEN"),
|
18
|
+
usso_api_key: str | None = os.getenv("USSO_ADMIN_API_KEY"),
|
19
|
+
user_id: str | None = None,
|
20
|
+
):
|
21
|
+
requests.Session.__init__(self)
|
22
|
+
BaseUssoSession.__init__(
|
23
|
+
self,
|
24
|
+
usso_base_url=usso_base_url,
|
25
|
+
api_key=api_key,
|
26
|
+
usso_refresh_url=usso_refresh_url,
|
27
|
+
refresh_token=refresh_token,
|
28
|
+
usso_api_key=usso_api_key,
|
29
|
+
user_id=user_id,
|
30
|
+
)
|
31
|
+
self.headers.update(self.headers)
|
32
|
+
|
33
|
+
def _refresh_api(self):
|
34
|
+
assert self.usso_api_key, "usso_api_key is required"
|
35
|
+
params = {"user_id": self.user_id} if self.user_id else {}
|
36
|
+
response = requests.get(
|
37
|
+
f"{self.usso_refresh_url}/api",
|
38
|
+
headers={"x-api-key": self.usso_api_key},
|
39
|
+
params=params,
|
40
|
+
)
|
41
|
+
response.raise_for_status()
|
42
|
+
data: dict = response.json()
|
43
|
+
self._refresh_token = data.get("token", {}).get("refresh_token")
|
44
|
+
|
45
|
+
def _refresh(self):
|
46
|
+
assert (
|
47
|
+
self.refresh_token or self.usso_api_key
|
48
|
+
), "refresh_token or usso_api_key is required"
|
49
|
+
|
50
|
+
if self.usso_api_key and not self.refresh_token:
|
51
|
+
self._refresh_api()
|
52
|
+
|
53
|
+
response = requests.post(
|
54
|
+
self.usso_refresh_url, json={"refresh_token": f"{self.refresh_token}"}
|
55
|
+
)
|
56
|
+
response.raise_for_status()
|
57
|
+
self.access_token = response.json().get("access_token")
|
58
|
+
self.headers.update({"Authorization": f"Bearer {self.access_token}"})
|
59
|
+
return response.json()
|
60
|
+
|
61
|
+
def get_session(self):
|
62
|
+
if self.api_key:
|
63
|
+
return self
|
64
|
+
|
65
|
+
if not self.access_token or is_expired(self.access_token):
|
66
|
+
self._refresh()
|
67
|
+
return self
|
68
|
+
|
69
|
+
def _request(self, method: str, url: str, **kwargs):
|
70
|
+
self.get_session()
|
71
|
+
return requests.Session.request(self, method, url, **kwargs)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: usso
|
3
|
-
Version: 0.27.
|
3
|
+
Version: 0.27.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>
|
@@ -81,7 +81,7 @@ The USSO-Client provides a universal single sign-on (SSO) integration for micros
|
|
81
81
|
Install the USSO client using pip:
|
82
82
|
|
83
83
|
```bash
|
84
|
-
pip install usso
|
84
|
+
pip install usso
|
85
85
|
```
|
86
86
|
|
87
87
|
To add framework-specific support, use the following commands:
|
@@ -89,7 +89,13 @@ To add framework-specific support, use the following commands:
|
|
89
89
|
For FastAPI:
|
90
90
|
|
91
91
|
```bash
|
92
|
-
pip install "usso
|
92
|
+
pip install "usso[fastapi]"
|
93
|
+
```
|
94
|
+
|
95
|
+
For Django:
|
96
|
+
|
97
|
+
```bash
|
98
|
+
pip install "usso[django]"
|
93
99
|
```
|
94
100
|
|
95
101
|
## Quick Start
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|