usso 0.27.1__tar.gz → 0.27.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.
Files changed (31) hide show
  1. {usso-0.27.1/src/usso.egg-info → usso-0.27.2}/PKG-INFO +1 -1
  2. {usso-0.27.1 → usso-0.27.2}/pyproject.toml +1 -1
  3. usso-0.27.2/src/usso/client/__init__.py +4 -0
  4. {usso-0.27.1 → usso-0.27.2}/src/usso/client/async_api.py +32 -52
  5. {usso-0.27.1 → usso-0.27.2}/src/usso/django/middleware.py +1 -0
  6. usso-0.27.2/src/usso/session/__init__.py +4 -0
  7. {usso-0.27.1 → usso-0.27.2}/src/usso/session/session.py +1 -3
  8. {usso-0.27.1 → usso-0.27.2/src/usso.egg-info}/PKG-INFO +1 -1
  9. usso-0.27.1/src/usso/django/__init__.py +0 -0
  10. usso-0.27.1/src/usso/session/__init__.py +0 -0
  11. {usso-0.27.1 → usso-0.27.2}/LICENSE.txt +0 -0
  12. {usso-0.27.1 → usso-0.27.2}/README.md +0 -0
  13. {usso-0.27.1 → usso-0.27.2}/setup.cfg +0 -0
  14. {usso-0.27.1 → usso-0.27.2}/src/usso/__init__.py +0 -0
  15. {usso-0.27.1 → usso-0.27.2}/src/usso/b64tools.py +0 -0
  16. {usso-0.27.1 → usso-0.27.2}/src/usso/client/api.py +0 -0
  17. {usso-0.27.1 → usso-0.27.2}/src/usso/core.py +0 -0
  18. {usso-0.27.1/src/usso/client → usso-0.27.2/src/usso/django}/__init__.py +0 -0
  19. {usso-0.27.1 → usso-0.27.2}/src/usso/exceptions.py +0 -0
  20. {usso-0.27.1 → usso-0.27.2}/src/usso/fastapi/__init__.py +0 -0
  21. {usso-0.27.1 → usso-0.27.2}/src/usso/fastapi/integration.py +1 -1
  22. {usso-0.27.1 → usso-0.27.2}/src/usso/schemas.py +0 -0
  23. {usso-0.27.1 → usso-0.27.2}/src/usso/session/async_session.py +0 -0
  24. {usso-0.27.1 → usso-0.27.2}/src/usso.egg-info/SOURCES.txt +0 -0
  25. {usso-0.27.1 → usso-0.27.2}/src/usso.egg-info/dependency_links.txt +0 -0
  26. {usso-0.27.1 → usso-0.27.2}/src/usso.egg-info/entry_points.txt +0 -0
  27. {usso-0.27.1 → usso-0.27.2}/src/usso.egg-info/requires.txt +0 -0
  28. {usso-0.27.1 → usso-0.27.2}/src/usso.egg-info/top_level.txt +0 -0
  29. {usso-0.27.1 → usso-0.27.2}/tests/test_api.py +0 -0
  30. {usso-0.27.1 → usso-0.27.2}/tests/test_core.py +0 -0
  31. {usso-0.27.1 → usso-0.27.2}/tests/test_simple.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: usso
3
- Version: 0.27.1
3
+ Version: 0.27.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.27.1"
7
+ version = "0.27.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"
@@ -0,0 +1,4 @@
1
+ from .api import UssoAPI
2
+ from .async_api import AsyncUssoAPI
3
+
4
+ __all__ = ["UssoAPI", "AsyncUssoAPI"]
@@ -1,6 +1,6 @@
1
1
  import logging
2
2
 
3
- import aiohttp
3
+ import httpx
4
4
  from singleton import Singleton
5
5
 
6
6
  from usso.core import UserData, Usso
@@ -28,18 +28,16 @@ class AsyncUssoAPI(metaclass=Singleton):
28
28
  return
29
29
 
30
30
  url = f"{self.url}/auth/refresh"
31
+ headers = {
32
+ "Authorization": f"Bearer {self.refresh_token}",
33
+ "Content-Type": "application/json",
34
+ }
31
35
 
32
- if self.refresh_token:
33
- headers = {
34
- "Authorization": f"Bearer {self.refresh_token}",
35
- "content-type": "application/json",
36
- }
37
-
38
- async with aiohttp.ClientSession() as session:
39
- async with session.post(url, headers=headers) as resp:
40
- if kwargs.get("raise_exception", True):
41
- resp.raise_for_status()
42
- self.access_token = (await resp.json()).get("access_token")
36
+ async with httpx.AsyncClient() as client:
37
+ resp = await client.post(url, headers=headers)
38
+ if kwargs.get("raise_exception", True):
39
+ resp.raise_for_status()
40
+ self.access_token = resp.json().get("access_token")
43
41
 
44
42
  def _access_valid(self) -> bool:
45
43
  if not self.access_token:
@@ -48,9 +46,7 @@ class AsyncUssoAPI(metaclass=Singleton):
48
46
  user_data = Usso(
49
47
  jwks_url=f"{self.url}/website/jwks.json?"
50
48
  ).user_data_from_token(self.access_token)
51
- if user_data:
52
- return True
53
- return False
49
+ return bool(user_data)
54
50
 
55
51
  async def _request(
56
52
  self,
@@ -60,7 +56,7 @@ class AsyncUssoAPI(metaclass=Singleton):
60
56
  **kwargs,
61
57
  ) -> dict:
62
58
  url = f"{self.url}/{endpoint}"
63
- headers = {"content-type": "application/json"}
59
+ headers = {"Content-Type": "application/json"}
64
60
  if self.api_key:
65
61
  headers["x-api-key"] = self.api_key
66
62
  elif self.refresh_token:
@@ -68,54 +64,41 @@ class AsyncUssoAPI(metaclass=Singleton):
68
64
  await self._refresh()
69
65
  headers["Authorization"] = f"Bearer {self.access_token}"
70
66
 
71
- async with aiohttp.ClientSession() as session:
72
- async with session.request(
73
- method,
74
- url,
75
- headers=headers,
76
- json=data,
77
- ) as resp:
78
- try:
79
- resp_json = await resp.json()
80
- resp.raise_for_status()
81
- except aiohttp.ClientError as e:
82
- logging.error(f"Error: {e}")
83
- logging.error(f"Response: {resp_json}")
84
- raise e
85
- except Exception as e:
86
- logging.error(f"Error: {e}")
87
- logging.error(f"Response: {resp.text}")
88
- raise e
89
- return await resp.json()
67
+ async with httpx.AsyncClient() as client:
68
+ try:
69
+ resp = await client.request(
70
+ method,
71
+ url,
72
+ headers=headers,
73
+ json=data,
74
+ )
75
+ resp.raise_for_status()
76
+ return resp.json()
77
+ except httpx.HTTPStatusError as e:
78
+ logging.error(f"HTTP error: {e.response.status_code} {e.response.text}")
79
+ raise e
80
+ except Exception as e:
81
+ logging.error(f"Unexpected error: {e}")
82
+ raise e
90
83
 
91
84
  async def get_users(self, **kwargs) -> list[UserData]:
92
85
  users_dict = await self._request(endpoint="website/users", **kwargs)
93
-
94
86
  return [UserData(user_id=user.get("uid"), **user) for user in users_dict]
95
87
 
96
88
  async def get_user(self, user_id: str, **kwargs) -> UserData:
97
- user_dict = await self._request(
98
- endpoint=f"website/users/{user_id}",
99
- **kwargs,
100
- )
89
+ user_dict = await self._request(endpoint=f"website/users/{user_id}", **kwargs)
101
90
  return UserData(user_id=user_dict.get("uid"), **user_dict)
102
91
 
103
92
  async def get_user_by_credentials(self, credentials: dict, **kwargs) -> UserData:
104
93
  user_dict = await self._request(
105
- endpoint="website/users/credentials",
106
- data=credentials,
107
- **kwargs,
94
+ endpoint="website/users/credentials", data=credentials, **kwargs
108
95
  )
109
96
  return UserData(user_id=user_dict.get("uid"), **user_dict)
110
97
 
111
98
  async def create_user(self, user_data: dict, **kwargs) -> UserData:
112
99
  user_dict = await self._request(
113
- method="post",
114
- endpoint="website/users",
115
- data=user_data,
116
- **kwargs,
100
+ method="post", endpoint="website/users", data=user_data, **kwargs
117
101
  )
118
-
119
102
  return UserData(user_id=user_dict.get("uid"), **user_dict)
120
103
 
121
104
  async def create_user_credentials(
@@ -139,10 +122,7 @@ class AsyncUssoAPI(metaclass=Singleton):
139
122
  if credentials:
140
123
  user_data["authenticators"] = [credentials]
141
124
  user_dict = await self._request(
142
- method="post",
143
- endpoint="website/users",
144
- data=credentials,
145
- **kwargs,
125
+ method="post", endpoint="website/users", data=credentials, **kwargs
146
126
  )
147
127
  return UserData(user_id=user_dict.get("uid"), **user_dict)
148
128
 
@@ -6,6 +6,7 @@ from django.db.utils import IntegrityError
6
6
  from django.http import JsonResponse
7
7
  from django.http.request import HttpRequest
8
8
  from django.utils.deprecation import MiddlewareMixin
9
+
9
10
  from usso import UserData, Usso, USSOException
10
11
 
11
12
  logger = logging.getLogger("usso")
@@ -0,0 +1,4 @@
1
+ from .async_session import AsyncUssoSession
2
+ from .session import UssoSession
3
+
4
+ __all__ = ["UssoSession", "AsyncUssoSession"]
@@ -1,13 +1,11 @@
1
1
  from urllib.parse import urlparse
2
2
 
3
3
  import requests
4
- from singleton import Singleton
5
4
 
6
5
  from ..core import is_expired
7
6
 
8
7
 
9
- class BaseUssoSession(metaclass=Singleton):
10
-
8
+ class BaseUssoSession:
11
9
  def __init__(
12
10
  self,
13
11
  usso_base_url: str | None = None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: usso
3
- Version: 0.27.1
3
+ Version: 0.27.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>
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
@@ -1,8 +1,8 @@
1
1
  import logging
2
2
 
3
+ from fastapi import Request, WebSocket
3
4
  from starlette.status import HTTP_401_UNAUTHORIZED
4
5
 
5
- from fastapi import Request, WebSocket
6
6
  from usso.exceptions import USSOException
7
7
 
8
8
  from ..core import UserData, Usso, get_authorization_scheme_param
File without changes
File without changes
File without changes
File without changes