usso 0.21.0__py3-none-any.whl → 0.21.2__py3-none-any.whl

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/api.py CHANGED
@@ -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
 
usso/core.py CHANGED
@@ -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
 
usso/session.py CHANGED
@@ -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>
@@ -0,0 +1,15 @@
1
+ usso/__init__.py,sha256=RN0E6HI9kHedvDxheDPVWiAmh-169IrhXfvq_sHphQc,65
2
+ usso/api.py,sha256=MnUg-DcrmMXW1CxEcRlJQhIYl5J1WKvjqHQOz7jsrwE,5137
3
+ usso/b64tools.py,sha256=7lsz_Rn6PITkKWfjcebmewdhvFs2A7H4t_WE33MgZ0Y,626
4
+ usso/core.py,sha256=bJPKxJLcYe5zWoiNM_n9ajHSP5bARN8u9tsRQ6fLnyA,3998
5
+ usso/exceptions.py,sha256=hawOAuVbvQtjgRfwp1KFZ4SmV7fh720y5Gom9JVA8W8,504
6
+ usso/package_data.dat,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ usso/session.py,sha256=S3dFXzar0Pcwxj5TGqadKwGdmzmzgp4H2W3brfOwJ6A,1184
8
+ usso/fastapi/__init__.py,sha256=TRTDVJo8bwZQDAuCQFhh-g1XbIspf6TdFYXGAO5cgAU,130
9
+ usso/fastapi/integration.py,sha256=-zW3dwyvnVx59DgtV8JKL6YwG_ksFY2dOMwZAtwmEmY,1816
10
+ usso-0.21.2.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
11
+ usso-0.21.2.dist-info/METADATA,sha256=8SFgZ3XwcJmXcqVeUop5ziHwRivUMn2ilTQjWgwFqR4,4234
12
+ usso-0.21.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
13
+ usso-0.21.2.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
14
+ usso-0.21.2.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
15
+ usso-0.21.2.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- usso/__init__.py,sha256=RN0E6HI9kHedvDxheDPVWiAmh-169IrhXfvq_sHphQc,65
2
- usso/api.py,sha256=5bV82j8iPY0nxA7c5gZ8sFFZDm6KUdoG55ISuML3Ovc,5138
3
- usso/b64tools.py,sha256=7lsz_Rn6PITkKWfjcebmewdhvFs2A7H4t_WE33MgZ0Y,626
4
- usso/core.py,sha256=SCoN3GmUpj-AK6iFhmKquldfsiXtpJ6whGWKzk5NYFo,3950
5
- usso/exceptions.py,sha256=hawOAuVbvQtjgRfwp1KFZ4SmV7fh720y5Gom9JVA8W8,504
6
- usso/package_data.dat,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- usso/session.py,sha256=uj2iECBTtw3OJ_xflVkmutIrXCYQ-ag8WC_qB3IcDIs,842
8
- usso/fastapi/__init__.py,sha256=TRTDVJo8bwZQDAuCQFhh-g1XbIspf6TdFYXGAO5cgAU,130
9
- usso/fastapi/integration.py,sha256=NnySMqa-IKKYCi89m8Nrj2CD5xhBN_Kta74_Z_7FTI0,1817
10
- usso-0.21.0.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
11
- usso-0.21.0.dist-info/METADATA,sha256=74pS6SLw2Av0An2kW0FtWdx2IgQwf4UZfHbrk-mGElE,4234
12
- usso-0.21.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
13
- usso-0.21.0.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
14
- usso-0.21.0.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
15
- usso-0.21.0.dist-info/RECORD,,
File without changes