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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: usso
3
- Version: 0.21.0
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.0"
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"
@@ -2,7 +2,6 @@ import logging
2
2
 
3
3
  import requests
4
4
  from singleton import Singleton
5
-
6
5
  from usso.core import UserData, Usso
7
6
 
8
7
 
@@ -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",
@@ -2,7 +2,6 @@ import logging
2
2
 
3
3
  from fastapi import Request, WebSocket
4
4
  from starlette.status import HTTP_401_UNAUTHORIZED
5
-
6
5
  from usso.core import UserData, Usso
7
6
  from usso.exceptions import USSOException
8
7
 
@@ -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.0
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
- 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__":
@@ -10,7 +10,7 @@ class TestSimple(unittest.TestCase):
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