Tolerate a non-conformant peer#

Use this guide when a server sends payloads scim2-client refuses, or expects payloads it refuses to build. Two levers do that, at different grains: a check can be turned off for a whole payload, or a ScimPolicy can state how far a payload may depart from the specifications. See What the client checks for what the client checks in the first place.

Turn a check off#

Each check covers a whole payload, and each one is set on the client and overridden on a call:

check_request_payload

False expects a dict, and sends it as it is. Nothing is validated, and no attribute is filtered out by the context of the operation.

check_response_payload

False returns the payload of the response as a dict, without building a model from it.

raise_scim_errors

False returns the Error a server answered instead of raising it.

expected_status_codes

The codes the operation accepts, None for any. A code outside the list raises UnexpectedStatusCodeException.

# For every request this client makes
scim = SyncSCIMClient(client, check_response_payload=False)

# For this one only
payload = scim.query(User, "my-user-id", check_response_payload=False)

Two more are set on the client alone, for a server whose HTTP layer is at fault and not its payloads:

check_response_content_type

False accepts a response whose Content-Type is neither application/scim+json nor application/json.

check_response_status_codes

False accepts any status code, whatever expected_status_codes says.

Tip

Check the request Contexts to understand which values are excluded from a request payload, and which ones are expected in a response payload.

Send a raw body#

The extra arguments of an operation go to the engine, and replace what the client builds. With httpx and the in-process engines, content replaces the body. A raw body is sent without Content-Type, so pass it in headers. The response is read as usual:

error = scim.create(
    User(user_name="bjensen"),
    content=b'{"schemas": [',
    headers={"Content-Type": "application/scim+json"},
    raise_scim_errors=False,
)
assert error.scim_type == "invalidSyntax"

State how far a payload may depart#

Turning a check off gives up on a whole payload. When a server departs from the specifications on one point only, a ScimPolicy states which departure to accept, and everything else stays validated. The policy travels with the ScimProvider describing the server:

from scim2_models import ScimPolicy, ScimProvider, User

scim = SyncSCIMClient(
    client,
    provider=ScimProvider(
        models=[User],
        policy=ScimPolicy(unknown=ScimPolicy.Unknown.keep),
    ),
)
from scim2_models import ScimPolicy, ScimProvider, User

scim = AsyncSCIMClient(
    client,
    provider=ScimProvider(
        models=[User],
        policy=ScimPolicy(unknown=ScimPolicy.Unknown.keep),
    ),
)

Under Unknown.keep, an attribute no schema declares is read instead of refused, and written back to the server it came from:

user = scim.query(User, "my-user-id")
user.unknown_attributes["acmeDepartment"]

The client applies the policy to every payload it reads and it writes, so one provider covers both directions. Unknown.ignore reads the same payloads without sending those attributes back.

The policy belongs to scim2-models, and its guide lists every departure one can state — among them the remove operation carrying its target in value, which Microsoft Entra ID sends.