usso 0.28.17__tar.gz → 0.28.19__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 (35) hide show
  1. {usso-0.28.17/src/usso.egg-info → usso-0.28.19}/PKG-INFO +1 -1
  2. {usso-0.28.17 → usso-0.28.19}/pyproject.toml +1 -1
  3. {usso-0.28.17 → usso-0.28.19}/src/usso/auth/authorization.py +40 -1
  4. {usso-0.28.17 → usso-0.28.19}/src/usso/models/user.py +0 -1
  5. {usso-0.28.17 → usso-0.28.19/src/usso.egg-info}/PKG-INFO +1 -1
  6. {usso-0.28.17 → usso-0.28.19}/tests/test_authorization.py +46 -1
  7. {usso-0.28.17 → usso-0.28.19}/LICENSE.txt +0 -0
  8. {usso-0.28.17 → usso-0.28.19}/MANIFEST.in +0 -0
  9. {usso-0.28.17 → usso-0.28.19}/README.md +0 -0
  10. {usso-0.28.17 → usso-0.28.19}/pytest.ini +0 -0
  11. {usso-0.28.17 → usso-0.28.19}/setup.cfg +0 -0
  12. {usso-0.28.17 → usso-0.28.19}/src/usso/__init__.py +0 -0
  13. {usso-0.28.17 → usso-0.28.19}/src/usso/auth/__init__.py +0 -0
  14. {usso-0.28.17 → usso-0.28.19}/src/usso/auth/api_key.py +0 -0
  15. {usso-0.28.17 → usso-0.28.19}/src/usso/auth/client.py +0 -0
  16. {usso-0.28.17 → usso-0.28.19}/src/usso/auth/config.py +0 -0
  17. {usso-0.28.17 → usso-0.28.19}/src/usso/exceptions.py +0 -0
  18. {usso-0.28.17 → usso-0.28.19}/src/usso/integrations/django/__init__.py +0 -0
  19. {usso-0.28.17 → usso-0.28.19}/src/usso/integrations/django/middleware.py +0 -0
  20. {usso-0.28.17 → usso-0.28.19}/src/usso/integrations/fastapi/__init__.py +0 -0
  21. {usso-0.28.17 → usso-0.28.19}/src/usso/integrations/fastapi/dependency.py +0 -0
  22. {usso-0.28.17 → usso-0.28.19}/src/usso/integrations/fastapi/handler.py +0 -0
  23. {usso-0.28.17 → usso-0.28.19}/src/usso/session/__init__.py +0 -0
  24. {usso-0.28.17 → usso-0.28.19}/src/usso/session/async_session.py +0 -0
  25. {usso-0.28.17 → usso-0.28.19}/src/usso/session/base_session.py +0 -0
  26. {usso-0.28.17 → usso-0.28.19}/src/usso/session/session.py +0 -0
  27. {usso-0.28.17 → usso-0.28.19}/src/usso/utils/__init__.py +0 -0
  28. {usso-0.28.17 → usso-0.28.19}/src/usso/utils/method_utils.py +0 -0
  29. {usso-0.28.17 → usso-0.28.19}/src/usso/utils/string_utils.py +0 -0
  30. {usso-0.28.17 → usso-0.28.19}/src/usso.egg-info/SOURCES.txt +0 -0
  31. {usso-0.28.17 → usso-0.28.19}/src/usso.egg-info/dependency_links.txt +0 -0
  32. {usso-0.28.17 → usso-0.28.19}/src/usso.egg-info/entry_points.txt +0 -0
  33. {usso-0.28.17 → usso-0.28.19}/src/usso.egg-info/requires.txt +0 -0
  34. {usso-0.28.17 → usso-0.28.19}/src/usso.egg-info/top_level.txt +0 -0
  35. {usso-0.28.17 → usso-0.28.19}/tests/test_fastapi.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: usso
3
- Version: 0.28.17
3
+ Version: 0.28.19
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.28.17"
7
+ version = "0.28.19"
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,5 @@
1
1
  import fnmatch
2
+ import logging
2
3
  from urllib.parse import parse_qs, urlparse
3
4
 
4
5
  PRIVILEGE_LEVELS = {
@@ -136,7 +137,7 @@ def is_authorized(
136
137
  return False
137
138
 
138
139
  if requested_action:
139
- user_level = PRIVILEGE_LEVELS.get(user_action or "*", 999)
140
+ user_level = PRIVILEGE_LEVELS.get(user_action or "read", 10)
140
141
  req_level = PRIVILEGE_LEVELS.get(requested_action, 0)
141
142
  return user_level >= req_level
142
143
 
@@ -181,3 +182,41 @@ def check_access(
181
182
  print(f"auth failed {filter}, {scope}")
182
183
 
183
184
  return False
185
+
186
+
187
+ def is_subset_scope(*, subset_scope: str, super_scope: str) -> bool:
188
+ child_action, child_path, child_filters = parse_scope(subset_scope)
189
+ parent_action, parent_path, parent_filters = parse_scope(super_scope)
190
+
191
+ # 1. Compare privilege levels
192
+ child_level = PRIVILEGE_LEVELS.get(child_action or "read", 10)
193
+ parent_level = PRIVILEGE_LEVELS.get(parent_action or "read", 10)
194
+ if parent_level < child_level:
195
+ return False
196
+
197
+ # 2. Compare path
198
+ child_path_str = "/".join(child_path)
199
+ parent_path_str = "/".join(parent_path)
200
+ if not is_path_match(parent_path_str, child_path_str):
201
+ return False
202
+
203
+ # 3. Compare filters: parent_filters ⊆ child_filters
204
+ for k, v in parent_filters.items():
205
+ if child_filters.get(k) != v:
206
+ return False
207
+
208
+ logging.error(f"{parent_level}, {child_level}")
209
+
210
+ return True
211
+
212
+
213
+ def has_subset_scope(
214
+ *, subset_scope: str, user_scopes: list[str] | str | None
215
+ ) -> bool:
216
+ user_scopes = user_scopes or []
217
+ if isinstance(user_scopes, str):
218
+ user_scopes = [user_scopes]
219
+ for user_scope in user_scopes:
220
+ if is_subset_scope(subset_scope=subset_scope, super_scope=user_scope):
221
+ return True
222
+ return False
@@ -46,7 +46,6 @@ class UserData(BaseModel):
46
46
  nbf: int | None = None,
47
47
  exp: int | None = None,
48
48
  jti: str | None = None,
49
-
50
49
  token_type: TokenType | None = None,
51
50
  session_id: str | None = None,
52
51
  tenant_id: str | None = None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: usso
3
- Version: 0.28.17
3
+ Version: 0.28.19
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>
@@ -1,6 +1,11 @@
1
1
  import pytest
2
2
 
3
- from src.usso.auth.authorization import check_access, is_path_match
3
+ from src.usso.auth.authorization import (
4
+ check_access,
5
+ has_subset_scope,
6
+ is_path_match,
7
+ is_subset_scope,
8
+ )
4
9
 
5
10
 
6
11
  @pytest.mark.parametrize(
@@ -165,3 +170,43 @@ def test_minimal_params_success():
165
170
  def test_minimal_params_fail():
166
171
  scopes = ["read:file?*"]
167
172
  assert check_access(scopes, "file", "create") is False
173
+
174
+
175
+ def test_minimal_params_read_create_fail():
176
+ scopes = ["file"]
177
+ assert check_access(scopes, "file", "create") is False
178
+
179
+
180
+ def test_scope_subset():
181
+ assert is_subset_scope(
182
+ subset_scope="read:media/files?user_id=123",
183
+ super_scope="read:media/files",
184
+ )
185
+ assert is_subset_scope(
186
+ subset_scope="read:media/files?user_id=123", super_scope="read:media/*"
187
+ )
188
+ assert not is_subset_scope(
189
+ subset_scope="create:media/files", super_scope="read:media/files"
190
+ )
191
+ assert not is_subset_scope(
192
+ subset_scope="update:media/files", super_scope="read:media/files"
193
+ )
194
+ assert not is_subset_scope(
195
+ subset_scope="read:media/files?user_id=123",
196
+ super_scope="read:media/files?user_id=456",
197
+ )
198
+ assert not is_subset_scope(
199
+ subset_scope="read:media/files?user_id=123",
200
+ super_scope="read:media/files?workspace_id=123",
201
+ )
202
+ assert is_subset_scope(subset_scope="read:files", super_scope="read:*")
203
+ assert is_subset_scope(
204
+ subset_scope="read:files", super_scope="read://files"
205
+ )
206
+
207
+ assert has_subset_scope(
208
+ subset_scope="files", user_scopes=["read:files", "create:files"]
209
+ )
210
+ assert not is_subset_scope(
211
+ subset_scope="create:files", super_scope="files"
212
+ )
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
File without changes
File without changes