usso 0.28.13__tar.gz → 0.28.15__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 (33) hide show
  1. {usso-0.28.13/src/usso.egg-info → usso-0.28.15}/PKG-INFO +3 -3
  2. {usso-0.28.13 → usso-0.28.15}/README.md +1 -1
  3. {usso-0.28.13 → usso-0.28.15}/pyproject.toml +2 -2
  4. {usso-0.28.13 → usso-0.28.15}/src/usso/auth/api_key.py +3 -3
  5. {usso-0.28.13 → usso-0.28.15}/src/usso/auth/client.py +1 -1
  6. {usso-0.28.13 → usso-0.28.15}/src/usso/integrations/django/middleware.py +2 -2
  7. {usso-0.28.13 → usso-0.28.15}/src/usso/integrations/fastapi/dependency.py +8 -2
  8. {usso-0.28.13 → usso-0.28.15}/src/usso/session/async_session.py +2 -2
  9. {usso-0.28.13 → usso-0.28.15}/src/usso/session/base_session.py +3 -3
  10. {usso-0.28.13 → usso-0.28.15}/src/usso/session/session.py +1 -1
  11. {usso-0.28.13 → usso-0.28.15/src/usso.egg-info}/PKG-INFO +3 -3
  12. {usso-0.28.13 → usso-0.28.15}/src/usso.egg-info/requires.txt +1 -1
  13. {usso-0.28.13 → usso-0.28.15}/LICENSE.txt +0 -0
  14. {usso-0.28.13 → usso-0.28.15}/MANIFEST.in +0 -0
  15. {usso-0.28.13 → usso-0.28.15}/pytest.ini +0 -0
  16. {usso-0.28.13 → usso-0.28.15}/setup.cfg +0 -0
  17. {usso-0.28.13 → usso-0.28.15}/src/usso/__init__.py +0 -0
  18. {usso-0.28.13 → usso-0.28.15}/src/usso/auth/__init__.py +0 -0
  19. {usso-0.28.13 → usso-0.28.15}/src/usso/auth/config.py +0 -0
  20. {usso-0.28.13 → usso-0.28.15}/src/usso/exceptions.py +0 -0
  21. {usso-0.28.13 → usso-0.28.15}/src/usso/integrations/django/__init__.py +0 -0
  22. {usso-0.28.13 → usso-0.28.15}/src/usso/integrations/fastapi/__init__.py +0 -0
  23. {usso-0.28.13 → usso-0.28.15}/src/usso/integrations/fastapi/handler.py +0 -0
  24. {usso-0.28.13 → usso-0.28.15}/src/usso/models/user.py +0 -0
  25. {usso-0.28.13 → usso-0.28.15}/src/usso/session/__init__.py +0 -0
  26. {usso-0.28.13 → usso-0.28.15}/src/usso/utils/__init__.py +0 -0
  27. {usso-0.28.13 → usso-0.28.15}/src/usso/utils/method_utils.py +0 -0
  28. {usso-0.28.13 → usso-0.28.15}/src/usso/utils/string_utils.py +0 -0
  29. {usso-0.28.13 → usso-0.28.15}/src/usso.egg-info/SOURCES.txt +0 -0
  30. {usso-0.28.13 → usso-0.28.15}/src/usso.egg-info/dependency_links.txt +0 -0
  31. {usso-0.28.13 → usso-0.28.15}/src/usso.egg-info/entry_points.txt +0 -0
  32. {usso-0.28.13 → usso-0.28.15}/src/usso.egg-info/top_level.txt +0 -0
  33. {usso-0.28.13 → usso-0.28.15}/tests/test_fastapi.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: usso
3
- Version: 0.28.13
3
+ Version: 0.28.15
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>
@@ -28,7 +28,7 @@ Requires-Dist: cachetools
28
28
  Requires-Dist: singleton_package
29
29
  Requires-Dist: json-advanced
30
30
  Requires-Dist: httpx
31
- Requires-Dist: usso-jwt>=0.1.16
31
+ Requires-Dist: usso-jwt>=0.2.0
32
32
  Provides-Extra: fastapi
33
33
  Requires-Dist: fastapi>=0.65.0; extra == "fastapi"
34
34
  Requires-Dist: uvicorn[standard]>=0.13.0; extra == "fastapi"
@@ -148,7 +148,7 @@ Then configure your app to verify tokens issued by this service, using its publi
148
148
 
149
149
  ```python
150
150
  JWTConfig(
151
- jwk_url="http://localhost:8000/.well-known/jwks.json",
151
+ jwks_url="http://localhost:8000/.well-known/jwks.json",
152
152
  ...
153
153
  )
154
154
  ```
@@ -96,7 +96,7 @@ Then configure your app to verify tokens issued by this service, using its publi
96
96
 
97
97
  ```python
98
98
  JWTConfig(
99
- jwk_url="http://localhost:8000/.well-known/jwks.json",
99
+ jwks_url="http://localhost:8000/.well-known/jwks.json",
100
100
  ...
101
101
  )
102
102
  ```
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "usso"
7
- version = "0.28.13"
7
+ version = "0.28.15"
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"
@@ -30,7 +30,7 @@ dependencies = [
30
30
  "singleton_package",
31
31
  "json-advanced",
32
32
  "httpx",
33
- "usso-jwt>=0.1.16",
33
+ "usso-jwt>=0.2.0",
34
34
  ]
35
35
 
36
36
  [project.optional-dependencies]
@@ -20,11 +20,11 @@ def _handle_exception(error_type: str, **kwargs):
20
20
 
21
21
 
22
22
  @cachetools.func.ttl_cache(maxsize=128, ttl=10 * 60)
23
- def fetch_api_key_data(jwk_url: str, api_key: str):
23
+ def fetch_api_key_data(jwks_url: str, api_key: str):
24
24
  """Fetch user data using an API key.
25
25
 
26
26
  Args:
27
- jwk_url: The JWK URL to use for verification
27
+ jwks_url: The JWK URL to use for verification
28
28
  api_key: The API key to verify
29
29
 
30
30
  Returns:
@@ -34,7 +34,7 @@ def fetch_api_key_data(jwk_url: str, api_key: str):
34
34
  USSOException: If the API key is invalid or verification fails
35
35
  """
36
36
  try:
37
- parsed = urlparse(jwk_url)
37
+ parsed = urlparse(jwks_url)
38
38
  url = f"{parsed.scheme}://{parsed.netloc}/api_key/verify"
39
39
  response = httpx.post(url, json={"api_key": api_key})
40
40
  response.raise_for_status()
@@ -87,4 +87,4 @@ class UssoAuth:
87
87
  Raises:
88
88
  USSOException: If the API key is invalid
89
89
  """
90
- return fetch_api_key_data(self.jwt_configs[0].jwk_url, api_key)
90
+ return fetch_api_key_data(self.jwt_configs[0].jwks_url, api_key)
@@ -70,8 +70,8 @@ class USSOAuthenticationMiddleware(MiddlewareMixin):
70
70
  Check if a user exists by phone. If not, create a new user
71
71
  and return it.
72
72
  """
73
- if self.jwt_config.jwk_url:
74
- domain = urlparse(self.jwt_config.jwk_url).netloc
73
+ if self.jwt_config.jwks_url:
74
+ domain = urlparse(self.jwt_config.jwks_url).netloc
75
75
  else:
76
76
  domain = "example.com"
77
77
  phone = user_data.phone
@@ -16,12 +16,14 @@ class USSOAuthentication(UssoAuth):
16
16
  self,
17
17
  jwt_config: AvailableJwtConfigs | None = None,
18
18
  raise_exception: bool = True,
19
+ expected_token_type: str = "access",
19
20
  ):
20
21
  if jwt_config is None:
21
22
  jwt_config = AuthConfig()
22
23
 
23
24
  super().__init__(jwt_config=jwt_config)
24
25
  self.raise_exception = raise_exception
26
+ self.expected_token_type = expected_token_type
25
27
 
26
28
  def __call__(self, request: Request) -> UserData:
27
29
  return self.usso_access_security(request)
@@ -52,7 +54,9 @@ class USSOAuthentication(UssoAuth):
52
54
  token = self.get_request_jwt(request)
53
55
  if token:
54
56
  return self.user_data_from_token(
55
- token, raise_exception=self.raise_exception
57
+ token,
58
+ raise_exception=self.raise_exception,
59
+ expected_token_type=self.expected_token_type,
56
60
  )
57
61
 
58
62
  _handle_exception(
@@ -71,7 +75,9 @@ class USSOAuthentication(UssoAuth):
71
75
  token = self.get_request_jwt(websocket)
72
76
  if token:
73
77
  return self.user_data_from_token(
74
- token, raise_exception=self.raise_exception
78
+ token,
79
+ raise_exception=self.raise_exception,
80
+ expected_token_type=self.expected_token_type,
75
81
  )
76
82
  _handle_exception(
77
83
  "Unauthorized",
@@ -52,11 +52,11 @@ class AsyncUssoSession(httpx.AsyncClient, BaseUssoSession):
52
52
  data: dict[str, str | dict[str, str]] = response.json()
53
53
  self.access_token = JWT(
54
54
  token=data.get("access_token"),
55
- config=JWTConfig(jwk_url=f"{self.usso_url}/website/jwks.json"),
55
+ config=JWTConfig(jwks_url=f"{self.usso_url}/website/jwks.json"),
56
56
  )
57
57
  self._refresh_token = JWT(
58
58
  token=data.get("token", {}).get("refresh_token"),
59
- config=JWTConfig(jwk_url=f"{self.usso_url}/website/jwks.json"),
59
+ config=JWTConfig(jwks_url=f"{self.usso_url}/website/jwks.json"),
60
60
  )
61
61
  if self.access_token:
62
62
  self.headers.update({
@@ -48,7 +48,7 @@ class BaseUssoSession:
48
48
  self.usso_refresh_url = f"{usso_url}/auth/refresh"
49
49
  self._refresh_token = JWT(
50
50
  token=refresh_token,
51
- config=JWTConfig(jwk_url=f"{self.usso_url}/website/jwks.json"),
51
+ config=JWTConfig(jwks_url=f"{self.usso_url}/website/jwks.json"),
52
52
  )
53
53
 
54
54
  self.access_token = None
@@ -67,10 +67,10 @@ class BaseUssoSession:
67
67
  def refresh_token(self):
68
68
  if (
69
69
  self._refresh_token
70
- and self._refresh_token.verify(
70
+ and self._refresh_token.verify( # noqa: W503
71
71
  expected_token_type="refresh",
72
72
  )
73
- and self._refresh_token.is_temporally_valid()
73
+ and self._refresh_token.is_temporally_valid() # noqa: W503
74
74
  ):
75
75
  self._refresh_token = None
76
76
 
@@ -38,7 +38,7 @@ class UssoSession(httpx.Client, BaseUssoSession):
38
38
  response.raise_for_status()
39
39
  self.access_token = JWT(
40
40
  token=response.json().get("access_token"),
41
- config=JWTConfig(jwk_url=f"{self.usso_url}/website/jwks.json"),
41
+ config=JWTConfig(jwks_url=f"{self.usso_url}/website/jwks.json"),
42
42
  )
43
43
  self.headers.update({"Authorization": f"Bearer {self.access_token}"})
44
44
  return response.json()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: usso
3
- Version: 0.28.13
3
+ Version: 0.28.15
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>
@@ -28,7 +28,7 @@ Requires-Dist: cachetools
28
28
  Requires-Dist: singleton_package
29
29
  Requires-Dist: json-advanced
30
30
  Requires-Dist: httpx
31
- Requires-Dist: usso-jwt>=0.1.16
31
+ Requires-Dist: usso-jwt>=0.2.0
32
32
  Provides-Extra: fastapi
33
33
  Requires-Dist: fastapi>=0.65.0; extra == "fastapi"
34
34
  Requires-Dist: uvicorn[standard]>=0.13.0; extra == "fastapi"
@@ -148,7 +148,7 @@ Then configure your app to verify tokens issued by this service, using its publi
148
148
 
149
149
  ```python
150
150
  JWTConfig(
151
- jwk_url="http://localhost:8000/.well-known/jwks.json",
151
+ jwks_url="http://localhost:8000/.well-known/jwks.json",
152
152
  ...
153
153
  )
154
154
  ```
@@ -4,7 +4,7 @@ cachetools
4
4
  singleton_package
5
5
  json-advanced
6
6
  httpx
7
- usso-jwt>=0.1.16
7
+ usso-jwt>=0.2.0
8
8
 
9
9
  [all]
10
10
  fastapi>=0.65.0
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