usso 0.21.0__tar.gz → 0.21.2__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.21.0/src/usso.egg-info → usso-0.21.2}/PKG-INFO +1 -1
- {usso-0.21.0 → usso-0.21.2}/pyproject.toml +1 -1
- {usso-0.21.0 → usso-0.21.2}/src/usso/api.py +0 -1
- {usso-0.21.0 → usso-0.21.2}/src/usso/core.py +8 -8
- {usso-0.21.0 → usso-0.21.2}/src/usso/fastapi/integration.py +0 -1
- {usso-0.21.0 → usso-0.21.2}/src/usso/session.py +10 -0
- {usso-0.21.0 → usso-0.21.2/src/usso.egg-info}/PKG-INFO +1 -1
- {usso-0.21.0 → usso-0.21.2}/tests/test_api.py +11 -6
- {usso-0.21.0 → usso-0.21.2}/tests/test_simple.py +1 -1
- {usso-0.21.0 → usso-0.21.2}/LICENSE.txt +0 -0
- {usso-0.21.0 → usso-0.21.2}/README.md +0 -0
- {usso-0.21.0 → usso-0.21.2}/setup.cfg +0 -0
- {usso-0.21.0 → usso-0.21.2}/src/usso/__init__.py +0 -0
- {usso-0.21.0 → usso-0.21.2}/src/usso/b64tools.py +0 -0
- {usso-0.21.0 → usso-0.21.2}/src/usso/exceptions.py +0 -0
- {usso-0.21.0 → usso-0.21.2}/src/usso/fastapi/__init__.py +0 -0
- {usso-0.21.0 → usso-0.21.2}/src/usso/package_data.dat +0 -0
- {usso-0.21.0 → usso-0.21.2}/src/usso.egg-info/SOURCES.txt +0 -0
- {usso-0.21.0 → usso-0.21.2}/src/usso.egg-info/dependency_links.txt +0 -0
- {usso-0.21.0 → usso-0.21.2}/src/usso.egg-info/entry_points.txt +0 -0
- {usso-0.21.0 → usso-0.21.2}/src/usso.egg-info/requires.txt +0 -0
- {usso-0.21.0 → usso-0.21.2}/src/usso.egg-info/top_level.txt +0 -0
- {usso-0.21.0 → usso-0.21.2}/tests/test_core.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: usso
|
3
|
-
Version: 0.21.
|
3
|
+
Version: 0.21.2
|
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.21.
|
7
|
+
version = "0.21.2"
|
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"
|
@@ -79,40 +79,40 @@ class Usso(metaclass=Singleton):
|
|
79
79
|
decoded["token"] = token
|
80
80
|
return UserData(**decoded)
|
81
81
|
except jwt.exceptions.ExpiredSignatureError:
|
82
|
-
if kwargs.get("raise_exception"):
|
82
|
+
if kwargs.get("raise_exception", True):
|
83
83
|
raise USSOException(status_code=401, error="expired_signature")
|
84
84
|
except jwt.exceptions.InvalidSignatureError:
|
85
|
-
if kwargs.get("raise_exception"):
|
85
|
+
if kwargs.get("raise_exception", True):
|
86
86
|
raise USSOException(status_code=401, error="invalid_signature")
|
87
87
|
except jwt.exceptions.InvalidAlgorithmError:
|
88
|
-
if kwargs.get("raise_exception"):
|
88
|
+
if kwargs.get("raise_exception", True):
|
89
89
|
raise USSOException(
|
90
90
|
status_code=401,
|
91
91
|
error="invalid_algorithm",
|
92
92
|
)
|
93
93
|
except jwt.exceptions.InvalidIssuedAtError:
|
94
|
-
if kwargs.get("raise_exception"):
|
94
|
+
if kwargs.get("raise_exception", True):
|
95
95
|
raise USSOException(
|
96
96
|
status_code=401,
|
97
97
|
error="invalid_issued_at",
|
98
98
|
)
|
99
99
|
except jwt.exceptions.InvalidTokenError:
|
100
|
-
if kwargs.get("raise_exception"):
|
100
|
+
if kwargs.get("raise_exception", True):
|
101
101
|
raise USSOException(
|
102
102
|
status_code=401,
|
103
103
|
error="invalid_token",
|
104
104
|
)
|
105
105
|
except jwt.exceptions.InvalidKeyError:
|
106
|
-
if kwargs.get("raise_exception"):
|
106
|
+
if kwargs.get("raise_exception", True):
|
107
107
|
raise USSOException(
|
108
108
|
status_code=401,
|
109
109
|
error="invalid_key",
|
110
110
|
)
|
111
111
|
except USSOException as e:
|
112
|
-
if kwargs.get("raise_exception"):
|
112
|
+
if kwargs.get("raise_exception", True):
|
113
113
|
raise e
|
114
114
|
except Exception as e:
|
115
|
-
if kwargs.get("raise_exception"):
|
115
|
+
if kwargs.get("raise_exception", True):
|
116
116
|
raise USSOException(
|
117
117
|
status_code=401,
|
118
118
|
error="error",
|
@@ -1,3 +1,6 @@
|
|
1
|
+
from datetime import datetime
|
2
|
+
|
3
|
+
import jwt
|
1
4
|
import requests
|
2
5
|
|
3
6
|
|
@@ -20,6 +23,13 @@ class UssoSession:
|
|
20
23
|
return response.json()
|
21
24
|
|
22
25
|
def get_session(self):
|
26
|
+
if self.access_token:
|
27
|
+
decoded_token = jwt.decode(
|
28
|
+
self.access_token, options={"verify_signature": False}
|
29
|
+
)
|
30
|
+
exp = datetime.fromtimestamp(decoded_token.get("exp"))
|
31
|
+
if exp < datetime.now():
|
32
|
+
self.access_token = None
|
23
33
|
if not self.access_token:
|
24
34
|
self.access_token = self._refresh()["access_token"]
|
25
35
|
self.session.headers.update(
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: usso
|
3
|
-
Version: 0.21.
|
3
|
+
Version: 0.21.2
|
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>
|
@@ -18,17 +18,16 @@ class TestAPI(unittest.TestCase):
|
|
18
18
|
self.assertIsInstance(users, list)
|
19
19
|
for user in users:
|
20
20
|
self.assertIsInstance(user, UserData)
|
21
|
-
return users
|
22
21
|
|
23
22
|
def test_get_user(self):
|
24
|
-
|
23
|
+
usso_api = self.get_usso()
|
24
|
+
users = usso_api.get_users()
|
25
25
|
if len(users) == 0:
|
26
26
|
self.skipTest("No users found")
|
27
27
|
user = users[0]
|
28
28
|
usso_api = self.get_usso()
|
29
|
-
user = usso_api.get_user(user
|
29
|
+
user = usso_api.get_user(user.user_id)
|
30
30
|
self.assertIsInstance(user, UserData)
|
31
|
-
return user
|
32
31
|
|
33
32
|
def test_get_user_by_credentials(self):
|
34
33
|
usso_api = self.get_usso()
|
@@ -43,13 +42,19 @@ class TestAPI(unittest.TestCase):
|
|
43
42
|
}
|
44
43
|
user = usso_api.get_user_by_credentials(cred)
|
45
44
|
self.assertIsInstance(user, UserData)
|
46
|
-
return user
|
47
45
|
|
48
46
|
def test_create_user_by_credentials(self):
|
47
|
+
import requests
|
48
|
+
|
49
49
|
usso_api = self.get_usso()
|
50
50
|
telegram_id = os.getenv("TELEGRAM_ID")
|
51
51
|
cred = {"auth_method": "telegram", "representor": telegram_id}
|
52
|
-
|
52
|
+
try:
|
53
|
+
usso_api.create_user_by_credentials(credentials=cred)
|
54
|
+
except requests.HTTPError as e:
|
55
|
+
if e.response.status_code == 400:
|
56
|
+
if e.response.json().get("error") == "already_exists":
|
57
|
+
self.skipTest("Credential already exists")
|
53
58
|
|
54
59
|
|
55
60
|
if __name__ == "__main__":
|
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
|