usso 0.20.7__tar.gz → 0.21.0__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.20.7/src/usso.egg-info → usso-0.21.0}/PKG-INFO +1 -1
- {usso-0.20.7 → usso-0.21.0}/pyproject.toml +1 -1
- {usso-0.20.7 → usso-0.21.0}/src/usso/api.py +6 -2
- {usso-0.20.7 → usso-0.21.0}/src/usso/b64tools.py +5 -2
- {usso-0.20.7 → usso-0.21.0}/src/usso/core.py +27 -7
- usso-0.21.0/src/usso/session.py +28 -0
- {usso-0.20.7 → usso-0.21.0/src/usso.egg-info}/PKG-INFO +1 -1
- {usso-0.20.7 → usso-0.21.0}/src/usso.egg-info/SOURCES.txt +1 -0
- {usso-0.20.7 → usso-0.21.0}/LICENSE.txt +0 -0
- {usso-0.20.7 → usso-0.21.0}/README.md +0 -0
- {usso-0.20.7 → usso-0.21.0}/setup.cfg +0 -0
- {usso-0.20.7 → usso-0.21.0}/src/usso/__init__.py +0 -0
- {usso-0.20.7 → usso-0.21.0}/src/usso/exceptions.py +0 -0
- {usso-0.20.7 → usso-0.21.0}/src/usso/fastapi/__init__.py +0 -0
- {usso-0.20.7 → usso-0.21.0}/src/usso/fastapi/integration.py +0 -0
- {usso-0.20.7 → usso-0.21.0}/src/usso/package_data.dat +0 -0
- {usso-0.20.7 → usso-0.21.0}/src/usso.egg-info/dependency_links.txt +0 -0
- {usso-0.20.7 → usso-0.21.0}/src/usso.egg-info/entry_points.txt +0 -0
- {usso-0.20.7 → usso-0.21.0}/src/usso.egg-info/requires.txt +0 -0
- {usso-0.20.7 → usso-0.21.0}/src/usso.egg-info/top_level.txt +0 -0
- {usso-0.20.7 → usso-0.21.0}/tests/test_api.py +0 -0
- {usso-0.20.7 → usso-0.21.0}/tests/test_core.py +0 -0
- {usso-0.20.7 → usso-0.21.0}/tests/test_simple.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: usso
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.21.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>
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "usso"
|
7
|
-
version = "0.
|
7
|
+
version = "0.21.0"
|
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"
|
@@ -88,7 +88,9 @@ class UssoAPI(metaclass=Singleton):
|
|
88
88
|
def get_users(self, **kwargs) -> list[UserData]:
|
89
89
|
users_dict = self._request(endpoint="website/users", **kwargs)
|
90
90
|
|
91
|
-
return [
|
91
|
+
return [
|
92
|
+
UserData(user_id=user.get("uid"), **user) for user in users_dict
|
93
|
+
]
|
92
94
|
|
93
95
|
def get_user(self, user_id: str, **kwargs) -> UserData:
|
94
96
|
user_dict = self._request(
|
@@ -144,7 +146,9 @@ class UssoAPI(metaclass=Singleton):
|
|
144
146
|
return UserData(user_id=user_dict.get("uid"), **user_dict)
|
145
147
|
|
146
148
|
def get_user_payload(self, user_id: str, **kwargs) -> dict:
|
147
|
-
return self._request(
|
149
|
+
return self._request(
|
150
|
+
endpoint=f"website/users/{user_id}/payload", **kwargs
|
151
|
+
)
|
148
152
|
|
149
153
|
def update_user_payload(
|
150
154
|
self,
|
@@ -2,8 +2,11 @@ import base64
|
|
2
2
|
import uuid
|
3
3
|
|
4
4
|
|
5
|
-
def b64_encode_uuid(uuid_str):
|
6
|
-
|
5
|
+
def b64_encode_uuid(uuid_str: uuid.UUID | str):
|
6
|
+
uuid_UUID = (
|
7
|
+
uuid_str if isinstance(uuid_str, uuid.UUID) else uuid.UUID(uuid_str)
|
8
|
+
)
|
9
|
+
uuid_bytes = uuid_UUID.bytes
|
7
10
|
encoded_uuid = base64.urlsafe_b64encode(uuid_bytes).decode()
|
8
11
|
return encoded_uuid
|
9
12
|
|
@@ -71,23 +71,46 @@ class Usso(metaclass=Singleton):
|
|
71
71
|
signing_key.key,
|
72
72
|
algorithms=["RS256"],
|
73
73
|
)
|
74
|
+
if decoded["token_type"] != "access":
|
75
|
+
raise USSOException(
|
76
|
+
status_code=401,
|
77
|
+
error="invalid_token_type",
|
78
|
+
)
|
74
79
|
decoded["token"] = token
|
75
|
-
|
80
|
+
return UserData(**decoded)
|
76
81
|
except jwt.exceptions.ExpiredSignatureError:
|
77
82
|
if kwargs.get("raise_exception"):
|
78
83
|
raise USSOException(status_code=401, error="expired_signature")
|
79
|
-
return None
|
80
84
|
except jwt.exceptions.InvalidSignatureError:
|
81
85
|
if kwargs.get("raise_exception"):
|
82
86
|
raise USSOException(status_code=401, error="invalid_signature")
|
83
|
-
|
87
|
+
except jwt.exceptions.InvalidAlgorithmError:
|
88
|
+
if kwargs.get("raise_exception"):
|
89
|
+
raise USSOException(
|
90
|
+
status_code=401,
|
91
|
+
error="invalid_algorithm",
|
92
|
+
)
|
93
|
+
except jwt.exceptions.InvalidIssuedAtError:
|
94
|
+
if kwargs.get("raise_exception"):
|
95
|
+
raise USSOException(
|
96
|
+
status_code=401,
|
97
|
+
error="invalid_issued_at",
|
98
|
+
)
|
84
99
|
except jwt.exceptions.InvalidTokenError:
|
85
100
|
if kwargs.get("raise_exception"):
|
86
101
|
raise USSOException(
|
87
102
|
status_code=401,
|
88
103
|
error="invalid_token",
|
89
104
|
)
|
90
|
-
|
105
|
+
except jwt.exceptions.InvalidKeyError:
|
106
|
+
if kwargs.get("raise_exception"):
|
107
|
+
raise USSOException(
|
108
|
+
status_code=401,
|
109
|
+
error="invalid_key",
|
110
|
+
)
|
111
|
+
except USSOException as e:
|
112
|
+
if kwargs.get("raise_exception"):
|
113
|
+
raise e
|
91
114
|
except Exception as e:
|
92
115
|
if kwargs.get("raise_exception"):
|
93
116
|
raise USSOException(
|
@@ -96,6 +119,3 @@ class Usso(metaclass=Singleton):
|
|
96
119
|
message=str(e),
|
97
120
|
)
|
98
121
|
logger.error(e)
|
99
|
-
return None
|
100
|
-
|
101
|
-
return UserData(**decoded)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import requests
|
2
|
+
|
3
|
+
|
4
|
+
class UssoSession:
|
5
|
+
def __init__(self, sso_refresh_url: str, refresh_token: str | None = None):
|
6
|
+
self.sso_refresh_url = sso_refresh_url
|
7
|
+
self.refresh_token = refresh_token
|
8
|
+
self.session = requests.Session()
|
9
|
+
self.access_token = None
|
10
|
+
|
11
|
+
def _refresh(self):
|
12
|
+
if not self.refresh_token:
|
13
|
+
return
|
14
|
+
|
15
|
+
response = requests.post(
|
16
|
+
self.sso_refresh_url,
|
17
|
+
json={"refresh_token": f"{self.refresh_token}"},
|
18
|
+
)
|
19
|
+
response.raise_for_status()
|
20
|
+
return response.json()
|
21
|
+
|
22
|
+
def get_session(self):
|
23
|
+
if not self.access_token:
|
24
|
+
self.access_token = self._refresh()["access_token"]
|
25
|
+
self.session.headers.update(
|
26
|
+
{"Authorization": f"Bearer {self.access_token}"}
|
27
|
+
)
|
28
|
+
return self.session
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: usso
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.21.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>
|
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
|