scim2-server 0.8.6__tar.gz → 0.8.7__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.
- {scim2_server-0.8.6 → scim2_server-0.8.7}/PKG-INFO +1 -1
- {scim2_server-0.8.6 → scim2_server-0.8.7}/pyproject.toml +1 -1
- {scim2_server-0.8.6 → scim2_server-0.8.7}/pyproject.toml.orig +1 -1
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/applications/base.py +28 -2
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/applications/wsgi.py +10 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/memory.py +14 -1
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/service.py +62 -1
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/storage.py +11 -3
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/testing.py +46 -6
- {scim2_server-0.8.6 → scim2_server-0.8.7}/LICENSE +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/README.md +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/__init__.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/applications/__init__.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/applications/asgi.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/bulk.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/conditions.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/cursor.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/errors.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/handler.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/py.typed +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/requests.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/resources/default-resource-types.json +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/resources/default-schemas.json +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/resources/default-service-provider-config.json +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/responses.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/routing.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/testserver/__init__.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/testserver/application.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/testserver/cli.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/testserver/oauth.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/testserver/precis.py +0 -0
- {scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/utils.py +0 -0
|
@@ -66,7 +66,20 @@ class BaseApplication:
|
|
|
66
66
|
|
|
67
67
|
It returns :data:`None` by default. Override it to pass the subject
|
|
68
68
|
that :meth:`check_auth` authenticated to the service, for
|
|
69
|
-
:meth:`~scim2_server.service.ScimService.authorize` and ``/Me``.
|
|
69
|
+
:meth:`~scim2_server.service.ScimService.authorize` and ``/Me``. The
|
|
70
|
+
following application passes the identifier of the user of a bearer
|
|
71
|
+
token:
|
|
72
|
+
|
|
73
|
+
>>> from scim2_server.applications.wsgi import WSGIApplication
|
|
74
|
+
>>> TOKENS = {"secret": "2819c223"}
|
|
75
|
+
>>> class TokenApplication(WSGIApplication):
|
|
76
|
+
... def get_subject(self, request):
|
|
77
|
+
... header = request.header("Authorization") or ""
|
|
78
|
+
... _, _, token = header.partition(" ")
|
|
79
|
+
... return TOKENS.get(token)
|
|
80
|
+
|
|
81
|
+
:doc:`/how-to/authenticate-the-clients` uses the subject to check the
|
|
82
|
+
rights of the client.
|
|
70
83
|
"""
|
|
71
84
|
return None
|
|
72
85
|
|
|
@@ -78,7 +91,20 @@ class BaseApplication:
|
|
|
78
91
|
whose credentials are missing or invalid. Check the rights of the
|
|
79
92
|
client in :meth:`~scim2_server.service.ScimService.authorize`, which
|
|
80
93
|
sees each operation of a bulk request. It is not called for
|
|
81
|
-
``/ServiceProviderConfig`` (:rfc:`RFC 7643 §5 <7643#section-5>`).
|
|
94
|
+
``/ServiceProviderConfig`` (:rfc:`RFC 7643 §5 <7643#section-5>`). The
|
|
95
|
+
following application accepts the bearer tokens of a dictionary:
|
|
96
|
+
|
|
97
|
+
>>> from scim2_models import UnauthorizedException
|
|
98
|
+
>>> from scim2_server.applications.wsgi import WSGIApplication
|
|
99
|
+
>>> TOKENS = {"secret": "2819c223"}
|
|
100
|
+
>>> class TokenApplication(WSGIApplication):
|
|
101
|
+
... def check_auth(self, request):
|
|
102
|
+
... header = request.header("Authorization") or ""
|
|
103
|
+
... scheme, _, token = header.partition(" ")
|
|
104
|
+
... if scheme.lower() != "bearer" or token not in TOKENS:
|
|
105
|
+
... raise UnauthorizedException(detail="Missing or invalid token")
|
|
106
|
+
|
|
107
|
+
:meth:`get_subject` then passes the client to the service.
|
|
82
108
|
"""
|
|
83
109
|
|
|
84
110
|
def needs_auth(self, request: ScimRequest) -> bool:
|
|
@@ -171,6 +171,16 @@ class TenantDispatcher:
|
|
|
171
171
|
|
|
172
172
|
Override this method to read the tenant from somewhere else, such as
|
|
173
173
|
a header or a sub-domain (:rfc:`RFC 7644 §6.1 <7644#section-6.1>`).
|
|
174
|
+
The following dispatcher reads the tenant in the sub-domain, such as
|
|
175
|
+
``acme`` in ``acme.scim.example``:
|
|
176
|
+
|
|
177
|
+
>>> class SubdomainDispatcher(TenantDispatcher):
|
|
178
|
+
... def select_tenant(self, environ):
|
|
179
|
+
... host = environ.get("HTTP_HOST", "").partition(":")[0].lower()
|
|
180
|
+
... tenant, _, domain = host.partition(".")
|
|
181
|
+
... if domain != "scim.example" or not self.is_valid_tenant(tenant):
|
|
182
|
+
... return None
|
|
183
|
+
... return tenant
|
|
174
184
|
"""
|
|
175
185
|
path_info: str = environ.get("PATH_INFO", "")
|
|
176
186
|
_, _, path = path_info.partition("/")
|
|
@@ -238,7 +238,20 @@ class InMemoryStorage(ScimStorage):
|
|
|
238
238
|
def generate_id(self, resource_type: ResourceType, resource: Resource[Any]) -> str:
|
|
239
239
|
"""Return the identifier of a new resource.
|
|
240
240
|
|
|
241
|
-
Override this method to get predictable identifiers.
|
|
241
|
+
Override this method to get predictable identifiers. The following
|
|
242
|
+
storage numbers the resources from 1:
|
|
243
|
+
|
|
244
|
+
>>> from itertools import count
|
|
245
|
+
>>> class NumberedStorage(InMemoryStorage):
|
|
246
|
+
... def __init__(self):
|
|
247
|
+
... super().__init__()
|
|
248
|
+
... self.ids = count(1)
|
|
249
|
+
...
|
|
250
|
+
... def generate_id(self, resource_type, resource):
|
|
251
|
+
... return str(next(self.ids))
|
|
252
|
+
>>> storage = NumberedStorage()
|
|
253
|
+
>>> storage.generate_id(None, None), storage.generate_id(None, None)
|
|
254
|
+
('1', '2')
|
|
242
255
|
"""
|
|
243
256
|
return uuid.uuid4().hex
|
|
244
257
|
|
|
@@ -269,6 +269,19 @@ class ScimService:
|
|
|
269
269
|
<scim2_server.requests.ScimRequest.subject>`. The exceptions it raises
|
|
270
270
|
answer the request.
|
|
271
271
|
|
|
272
|
+
The following service serves the user whose identifier is the
|
|
273
|
+
subject:
|
|
274
|
+
|
|
275
|
+
>>> from scim2_models import UnauthorizedException
|
|
276
|
+
>>> class MeService(ScimService):
|
|
277
|
+
... def me_target(self, request):
|
|
278
|
+
... if request.subject is None:
|
|
279
|
+
... raise UnauthorizedException
|
|
280
|
+
... return self.get_resource_type("User"), request.subject
|
|
281
|
+
|
|
282
|
+
:doc:`/how-to/serve-the-me-endpoint` also handles the subjects
|
|
283
|
+
without a user.
|
|
284
|
+
|
|
272
285
|
:raises ~scim2_models.NotImplementedException: By default, so that
|
|
273
286
|
``/Me`` answers 501.
|
|
274
287
|
:raises ~scim2_models.UnauthorizedException: When the request has no
|
|
@@ -288,6 +301,19 @@ class ScimService:
|
|
|
288
301
|
(:rfc:`RFC 7644 §7.6 <7644#section-7.6>`). Linking the created resource to the subject is left to the
|
|
289
302
|
application. The exceptions it raises answer the request.
|
|
290
303
|
|
|
304
|
+
The following service lets the authenticated clients create their
|
|
305
|
+
user:
|
|
306
|
+
|
|
307
|
+
>>> from scim2_models import UnauthorizedException
|
|
308
|
+
>>> class RegistrationService(ScimService):
|
|
309
|
+
... def me_creation_type(self, request):
|
|
310
|
+
... if request.subject is None:
|
|
311
|
+
... raise UnauthorizedException
|
|
312
|
+
... return self.get_resource_type("User")
|
|
313
|
+
|
|
314
|
+
:doc:`/how-to/serve-the-me-endpoint` also refuses the clients that
|
|
315
|
+
already have a user, and links the created user to the subject.
|
|
316
|
+
|
|
291
317
|
:raises ~scim2_models.NotImplementedException: By default, so that a
|
|
292
318
|
POST on ``/Me`` answers 501.
|
|
293
319
|
:raises ~scim2_models.UnauthorizedException: When the request has no
|
|
@@ -343,6 +369,20 @@ class ScimService:
|
|
|
343
369
|
:class:`~scim2_models.ForbiddenException` removes this type from the
|
|
344
370
|
search. The search answers 403 when every type is removed.
|
|
345
371
|
|
|
372
|
+
The following service lets the clients read, and refuses the other
|
|
373
|
+
operations:
|
|
374
|
+
|
|
375
|
+
>>> from scim2_models import ForbiddenException
|
|
376
|
+
>>> from scim2_server.routing import Operation
|
|
377
|
+
>>> READS = {Operation.query, Operation.search, Operation.search_with_body}
|
|
378
|
+
>>> class ReadOnlyService(ScimService):
|
|
379
|
+
... def authorize(self, request, target, resource_type):
|
|
380
|
+
... if target.operation not in READS:
|
|
381
|
+
... raise ForbiddenException(detail="Read-only access")
|
|
382
|
+
|
|
383
|
+
:doc:`/how-to/authenticate-the-clients` checks the scopes of a token
|
|
384
|
+
instead.
|
|
385
|
+
|
|
346
386
|
:raises ~scim2_models.ForbiddenException: When the client may not
|
|
347
387
|
perform the operation, for a 403.
|
|
348
388
|
:raises ~scim2_models.UnauthorizedException: When the request has no
|
|
@@ -548,7 +588,19 @@ class ScimService:
|
|
|
548
588
|
) -> str:
|
|
549
589
|
"""Return the URL of a resource.
|
|
550
590
|
|
|
551
|
-
Override this method to serve the resources at other URLs.
|
|
591
|
+
Override this method to serve the resources at other URLs. The
|
|
592
|
+
following service publishes the resources under the URL of a gateway:
|
|
593
|
+
|
|
594
|
+
>>> class GatewayService(ScimService):
|
|
595
|
+
... def resource_location(self, base_url, resource_type, resource_id):
|
|
596
|
+
... return f"https://api.example{resource_type.endpoint}/{resource_id}"
|
|
597
|
+
>>> from scim2_server.utils import load_default_provider
|
|
598
|
+
>>> service = GatewayService(load_default_provider())
|
|
599
|
+
>>> service.resource_location("", service.get_resource_type("User"), "42")
|
|
600
|
+
'https://api.example/Users/42'
|
|
601
|
+
|
|
602
|
+
:doc:`/how-to/publish-the-resources-at-other-urls` shows the effect on
|
|
603
|
+
the responses.
|
|
552
604
|
"""
|
|
553
605
|
assert resource_type.endpoint is not None
|
|
554
606
|
return (
|
|
@@ -1322,6 +1374,15 @@ class ScimService:
|
|
|
1322
1374
|
provider configuration, for the Bearer and Basic schemes. Override this
|
|
1323
1375
|
method to announce other schemes, or to add parameters to the
|
|
1324
1376
|
challenges, such as ``resource_metadata`` (:rfc:`RFC 9728 §5.1 <9728#section-5.1>`).
|
|
1377
|
+
The following service replaces the challenges with a single Bearer
|
|
1378
|
+
challenge that carries ``resource_metadata``:
|
|
1379
|
+
|
|
1380
|
+
>>> class ProtectedResourceService(ScimService):
|
|
1381
|
+
... def www_authenticate(self, exception):
|
|
1382
|
+
... url = "https://scim.example/.well-known/oauth-protected-resource"
|
|
1383
|
+
... return f'Bearer resource_metadata="{url}"'
|
|
1384
|
+
|
|
1385
|
+
:doc:`/how-to/authenticate-the-clients` shows the resulting header.
|
|
1325
1386
|
"""
|
|
1326
1387
|
schemes = self.config.authentication_schemes or []
|
|
1327
1388
|
challenges = dict.fromkeys(
|
|
@@ -121,8 +121,9 @@ class ScimStorage(ABC):
|
|
|
121
121
|
|
|
122
122
|
- Every resource it returns is a copy. Changing it does not change the
|
|
123
123
|
stored resource, and the resources it receives are not changed either.
|
|
124
|
-
- It fills ``id``, ``meta.resourceType
|
|
125
|
-
``meta.
|
|
124
|
+
- It fills ``id``, ``meta.resourceType`` and ``meta.version``. It fills
|
|
125
|
+
``meta.created`` and ``meta.lastModified`` when it stores them, and
|
|
126
|
+
leaves them empty otherwise. It leaves ``meta.location``
|
|
126
127
|
to the server, which knows the URLs. For the same reason, a reference
|
|
127
128
|
to another resource, such as ``members.$ref``, can be relative to the
|
|
128
129
|
SCIM root, such as ``Users/2819c223``. The server returns its URL.
|
|
@@ -282,7 +283,14 @@ class ScimStorage(ABC):
|
|
|
282
283
|
It does nothing by default. A SQL storage can open a savepoint here,
|
|
283
284
|
so that a failed operation does not prevent the next ones of a bulk
|
|
284
285
|
request (:rfc:`RFC 7644 §3.7 <7644#section-3.7>`). Committing the
|
|
285
|
-
request is left to the application.
|
|
286
|
+
request is left to the application. The following storage opens a
|
|
287
|
+
SQLAlchemy savepoint:
|
|
288
|
+
|
|
289
|
+
>>> class SQLStorage(ScimStorage):
|
|
290
|
+
... def operation(self):
|
|
291
|
+
... return self.session.begin_nested()
|
|
292
|
+
|
|
293
|
+
:doc:`/how-to/write-a-storage` describes the other methods.
|
|
286
294
|
"""
|
|
287
295
|
return nullcontext()
|
|
288
296
|
|
|
@@ -167,6 +167,19 @@ class ScimStorageContract:
|
|
|
167
167
|
:class:`~scim2_models.NotImplementedException` in that case.
|
|
168
168
|
"""
|
|
169
169
|
|
|
170
|
+
stores_created: bool = True
|
|
171
|
+
"""Whether the storage stores ``meta.created``.
|
|
172
|
+
|
|
173
|
+
Set it to :data:`False` for a storage that leaves ``meta.created`` empty.
|
|
174
|
+
"""
|
|
175
|
+
|
|
176
|
+
stores_last_modified: bool = True
|
|
177
|
+
"""Whether the storage stores ``meta.lastModified``.
|
|
178
|
+
|
|
179
|
+
Set it to :data:`False` for a storage that leaves ``meta.lastModified``
|
|
180
|
+
empty.
|
|
181
|
+
"""
|
|
182
|
+
|
|
170
183
|
@pytest.fixture
|
|
171
184
|
def provider(self) -> ScimProvider:
|
|
172
185
|
"""Return the description of the service the storage serves."""
|
|
@@ -248,16 +261,29 @@ class ScimStorageContract:
|
|
|
248
261
|
def test_create_fills_the_identifier_and_the_meta(
|
|
249
262
|
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
250
263
|
) -> None:
|
|
251
|
-
"""A created resource gets an id, its resource type
|
|
264
|
+
"""A created resource gets an id, its resource type and a version, but no location."""
|
|
252
265
|
(user,) = self.create_users(storage, user_type, user_model, "bjensen")
|
|
253
266
|
|
|
254
267
|
assert user.id
|
|
255
268
|
assert user.meta.resource_type == user_type.name
|
|
256
|
-
assert user.meta.created is not None
|
|
257
|
-
assert user.meta.last_modified == user.meta.created
|
|
258
269
|
assert user.meta.version
|
|
259
270
|
assert user.meta.location is None
|
|
260
271
|
|
|
272
|
+
def test_create_fills_the_stored_dates(
|
|
273
|
+
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
274
|
+
) -> None:
|
|
275
|
+
"""A created resource gets the dates the storage stores, and only them.
|
|
276
|
+
|
|
277
|
+
Per :rfc:`RFC 7643 §3.1 <7643#section-3.1>`, ``lastModified`` is
|
|
278
|
+
``created`` until the resource changes.
|
|
279
|
+
"""
|
|
280
|
+
(user,) = self.create_users(storage, user_type, user_model, "bjensen")
|
|
281
|
+
|
|
282
|
+
assert (user.meta.created is not None) is self.stores_created
|
|
283
|
+
assert (user.meta.last_modified is not None) is self.stores_last_modified
|
|
284
|
+
if self.stores_created and self.stores_last_modified:
|
|
285
|
+
assert user.meta.last_modified == user.meta.created
|
|
286
|
+
|
|
261
287
|
def test_create_does_not_change_the_given_resource(
|
|
262
288
|
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
263
289
|
) -> None:
|
|
@@ -294,6 +320,8 @@ class ScimStorageContract:
|
|
|
294
320
|
|
|
295
321
|
stored = storage.get(user_type, user.id)
|
|
296
322
|
assert stored.user_name == "bjensen"
|
|
323
|
+
assert stored.meta.created == user.meta.created
|
|
324
|
+
assert stored.meta.last_modified == user.meta.last_modified
|
|
297
325
|
assert stored.meta.version == user.meta.version
|
|
298
326
|
|
|
299
327
|
def test_get_returns_a_copy(
|
|
@@ -374,7 +402,7 @@ class ScimStorageContract:
|
|
|
374
402
|
def test_update_replaces_the_stored_resource(
|
|
375
403
|
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
376
404
|
) -> None:
|
|
377
|
-
"""An update stores the new state,
|
|
405
|
+
"""An update stores the new state, and changes the version."""
|
|
378
406
|
(user,) = self.create_users(storage, user_type, user_model, "bjensen")
|
|
379
407
|
user.display_name = "Barbara"
|
|
380
408
|
|
|
@@ -382,11 +410,23 @@ class ScimStorageContract:
|
|
|
382
410
|
|
|
383
411
|
assert updated.display_name == "Barbara"
|
|
384
412
|
assert storage.get(user_type, user.id).display_name == "Barbara"
|
|
385
|
-
assert updated.meta.created == user.meta.created
|
|
386
|
-
assert updated.meta.last_modified >= user.meta.created
|
|
387
413
|
assert updated.meta.version != user.meta.version
|
|
388
414
|
assert updated.meta.location is None
|
|
389
415
|
|
|
416
|
+
def test_update_keeps_the_creation_date(
|
|
417
|
+
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
418
|
+
) -> None:
|
|
419
|
+
"""An update keeps the creation date, and does not move the modification date back."""
|
|
420
|
+
(user,) = self.create_users(storage, user_type, user_model, "bjensen")
|
|
421
|
+
user.display_name = "Barbara"
|
|
422
|
+
|
|
423
|
+
updated = storage.update(user_type, user)
|
|
424
|
+
|
|
425
|
+
assert updated.meta.created == user.meta.created
|
|
426
|
+
assert (updated.meta.last_modified is not None) is self.stores_last_modified
|
|
427
|
+
if self.stores_last_modified:
|
|
428
|
+
assert updated.meta.last_modified >= user.meta.last_modified
|
|
429
|
+
|
|
390
430
|
def test_update_does_not_change_the_given_resource(
|
|
391
431
|
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
392
432
|
) -> None:
|
|
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
|
{scim2_server-0.8.6 → scim2_server-0.8.7}/scim2_server/resources/default-resource-types.json
RENAMED
|
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
|