usso 0.21.0__tar.gz → 0.21.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: usso
3
- Version: 0.21.0
3
+ Version: 0.21.1
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.0"
7
+ version = "0.21.1"
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,4 +1,6 @@
1
+ from datetime import datetime
1
2
  import requests
3
+ import jwt
2
4
 
3
5
 
4
6
  class UssoSession:
@@ -20,6 +22,11 @@ class UssoSession:
20
22
  return response.json()
21
23
 
22
24
  def get_session(self):
25
+ if self.access_token:
26
+ decoded_token = jwt.decode(self.access_token, options={"verify_signature": False})
27
+ exp = datetime.fromtimestamp(decoded_token.get("exp"))
28
+ if exp < datetime.now():
29
+ self.access_token = None
23
30
  if not self.access_token:
24
31
  self.access_token = self._refresh()["access_token"]
25
32
  self.session.headers.update(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: usso
3
- Version: 0.21.0
3
+ Version: 0.21.1
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
- users = self.test_get_users()
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["user_id"])
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
- usso_api.create_user_by_credentials(credentials=cred)
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__":
@@ -8,9 +8,9 @@ import unittest
8
8
  class TestSimple(unittest.TestCase):
9
9
  def test_import(self):
10
10
  import usso
11
-
11
+
12
12
  usso.Usso()
13
- usso.UserData()
13
+ usso.UserData(user_id='123')
14
14
 
15
15
 
16
16
  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