Reference¶
- class scim2_client.engines.httpx.SyncSCIMClient(client: Client, *args, **kwargs)[source]¶
Perform SCIM requests over the network and validate responses.
- Parameters:
client¶ – A
httpx.Clientinstance that will be used to send requests.resource_models¶ – A tuple of
Resourcetypes expected to be handled by the SCIM client. If a request payload describe a resource that is not in this list, an exception will be raised.check_request_payload¶ – If
False,resourceis expected to be a dict that will be passed as-is in the request. This value can be overwritten in methods.check_response_payload¶ – Whether to validate that the response payloads are valid. If set, the raw payload will be returned. This value can be overwritten in methods.
raise_scim_errors¶ – If
Trueand the server returned anErrorobject during a request, aSCIMResponseErrorObjectexception will be raised. IfFalsethe error object is returned. This value can be overwritten in methods.
- create(resource: AnyResource | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs) AnyResource | Error | dict[source]¶
Perform a POST request to create, as defined in RFC7644 §3.3.
- Parameters:
resource¶ – The resource to create If is a
dict, the resource type will be guessed from the schema.check_request_payload¶ – If set, overwrites
check_request_payload.check_response_payload¶ – If set, overwrites
check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
Creation of a User resource¶from scim2_models import User request = User(user_name="bjensen@example.com") response = scim.create(request) # 'response' may be a User or an Error object
Tip
Check the
RESOURCE_CREATION_REQUESTandRESOURCE_CREATION_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- query(resource_model: type[Resource] | None = None, id: str | None = None, query_parameters: ResponseParameters | dict | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 400, 307, 308, 401, 403, 404, 500], raise_scim_errors: bool | None = None, search_request: ResponseParameters | dict | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]¶
Perform a GET request to read resources, as defined in RFC7644 §3.4.2.
If id is not
None, the resource with the exact id will be reached.If id is
None, all the resources with the given type will be reached.
- Parameters:
query_parameters¶ – A
ResponseParametersorSearchRequestdetailing the query parameters. UseResponseParameterswhen querying a single resource by id, where onlyattributesandexcludedAttributesare meaningful (RFC 7644 §3.4.1). UseSearchRequestwhen listing resources, to also passfilter,sortBy,sortOrder,startIndexandcount(RFC 7644 §3.4.2).check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
Note
Querying a
ServiceProviderConfigwill return a single object, and not aListResponse.- Usage:
Query of a User resource knowing its id¶from scim2_models import User response = scim.query(User, "my-user-id) # 'response' may be a User or an Error object
Query of all the User resources filtering the ones with userName starts with john¶from scim2_models import User, SearchRequest req = SearchRequest(filter='userName sw "john"') response = scim.query(User, query_parameters=req) # 'response' may be a ListResponse[User] or an Error object
Query of all the available resources¶from scim2_models import User response = scim.query() # 'response' may be a ListResponse[Union[User, Group, ...]] or an Error object
Tip
Check the
RESOURCE_QUERY_REQUESTandRESOURCE_QUERY_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- search(search_request: SearchRequest | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]¶
Perform a POST search request to read all available resources, as defined in RFC7644 §3.4.3.
- Parameters:
resource_models¶ – Resource type or union of types expected to be read from the response.
search_request¶ – An object detailing the search query parameters.
check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
A
Errorobject in case of error.A
ListResponse[resource_model]object in case of success.
- Usage:
Searching for all the resources filtering the ones with id contains with admin¶from scim2_models import User, SearchRequest req = SearchRequest(filter='id co "john"') response = scim.search(search_request=search_request) # 'response' may be a ListResponse[User] or an Error object
Tip
Check the
SEARCH_REQUESTandSEARCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- delete(resource_model: type[Resource], id: str, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [204, 307, 308, 400, 401, 403, 404, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Error | dict | None[source]¶
Perform a DELETE request to create, as defined in RFC7644 §3.6.
- Parameters:
resource_model¶ – The type of the resource to delete.
id¶ – The type id the resource to delete.
check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Deleting an User which id is foobar¶from scim2_models import User, SearchRequest response = scim.delete(User, "foobar") # 'response' may be None, or an Error object
- replace(resource: AnyResource | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) AnyResource | Error | dict[source]¶
Perform a PUT request to replace a resource, as defined in RFC7644 §3.5.1.
- Parameters:
resource¶ – The new resource to replace. If is a
dict, the resource type will be guessed from the schema.check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
An
Errorobject in case of error.The updated object as returned by the server in case of success.
- Usage:
Replacement of a User resource¶from scim2_models import User user = scim.query(User, "my-used-id") user.display_name = "Fancy New Name" updated_user = scim.replace(user)
Tip
Check the
RESOURCE_REPLACEMENT_REQUESTandRESOURCE_REPLACEMENT_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- modify(resource_model: type[ResourceT], id: str, patch_op: PatchOp[TypeVar] | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 204, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) ResourceT | Error | dict | None[source]¶
Perform a PATCH request to modify a resource, as defined in RFC7644 §3.5.2.
- Parameters:
resource_model¶ – The type of the resource to modify.
id¶ – The id of the resource to modify.
patch_op¶ – The
PatchOpobject describing the modifications. Must be parameterized with the same resource type asresource_model(e.g.,PatchOp[User]whenresource_modelisUser).check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Modification of a User resource¶from scim2_models import User, PatchOp, PatchOperation operation = PatchOperation( op="replace", path="displayName", value="New Display Name" ) patch_op = PatchOp[User](operations=[operation]) response = scim.modify(User, "my-user-id", patch_op) # 'response' may be a User, None, or an Error object
Tip
Check the
RESOURCE_PATCH_REQUESTandRESOURCE_PATCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- class scim2_client.engines.httpx.AsyncSCIMClient(client: AsyncClient, *args, **kwargs)[source]¶
Perform SCIM requests over the network and validate responses.
- Parameters:
client¶ – A
httpx.AsyncClientinstance that will be used to send requests.resource_models¶ – A tuple of
Resourcetypes expected to be handled by the SCIM client. If a request payload describe a resource that is not in this list, an exception will be raised.check_request_payload¶ – If
False,resourceis expected to be a dict that will be passed as-is in the request. This value can be overwritten in methods.check_response_payload¶ – Whether to validate that the response payloads are valid. If set, the raw payload will be returned. This value can be overwritten in methods.
raise_scim_errors¶ – If
Trueand the server returned anErrorobject during a request, aSCIMResponseErrorObjectexception will be raised. IfFalsethe error object is returned. This value can be overwritten in methods.
- async create(resource: AnyResource | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs) AnyResource | Error | dict[source]¶
Perform a POST request to create, as defined in RFC7644 §3.3.
- Parameters:
resource¶ – The resource to create If is a
dict, the resource type will be guessed from the schema.check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
Creation of a User resource¶from scim2_models import User request = User(user_name="bjensen@example.com") response = scim.create(request) # 'response' may be a User or an Error object
Tip
Check the
RESOURCE_CREATION_REQUESTandRESOURCE_CREATION_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- async query(resource_model: type[Resource] | None = None, id: str | None = None, query_parameters: ResponseParameters | dict | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 400, 307, 308, 401, 403, 404, 500], raise_scim_errors: bool | None = None, search_request: ResponseParameters | dict | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]¶
Perform a GET request to read resources, as defined in RFC7644 §3.4.2.
If id is not
None, the resource with the exact id will be reached.If id is
None, all the resources with the given type will be reached.
- Parameters:
query_parameters¶ – A
ResponseParametersorSearchRequestdetailing the query parameters. UseResponseParameterswhen querying a single resource by id, where onlyattributesandexcludedAttributesare meaningful (RFC 7644 §3.4.1). UseSearchRequestwhen listing resources, to also passfilter,sortBy,sortOrder,startIndexandcount(RFC 7644 §3.4.2).check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
Note
Querying a
ServiceProviderConfigwill return a single object, and not aListResponse.- Usage:
Query of a User resource knowing its id¶from scim2_models import User response = scim.query(User, "my-user-id) # 'response' may be a User or an Error object
Query of all the User resources filtering the ones with userName starts with john¶from scim2_models import User, SearchRequest req = SearchRequest(filter='userName sw "john"') response = scim.query(User, query_parameters=req) # 'response' may be a ListResponse[User] or an Error object
Query of all the available resources¶from scim2_models import User response = scim.query() # 'response' may be a ListResponse[Union[User, Group, ...]] or an Error object
Tip
Check the
RESOURCE_QUERY_REQUESTandRESOURCE_QUERY_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- async search(search_request: SearchRequest | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]¶
Perform a POST search request to read all available resources, as defined in RFC7644 §3.4.3.
- Parameters:
resource_models¶ – Resource type or union of types expected to be read from the response.
search_request¶ – An object detailing the search query parameters.
check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
A
Errorobject in case of error.A
ListResponse[resource_model]object in case of success.
- Usage:
Searching for all the resources filtering the ones with id contains with admin¶from scim2_models import User, SearchRequest req = SearchRequest(filter='id co "john"') response = scim.search(search_request=search_request) # 'response' may be a ListResponse[User] or an Error object
Tip
Check the
SEARCH_REQUESTandSEARCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- async delete(resource_model: type[Resource], id: str, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [204, 307, 308, 400, 401, 403, 404, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Error | dict | None[source]¶
Perform a DELETE request to create, as defined in RFC7644 §3.6.
- Parameters:
resource_model¶ – The type of the resource to delete.
id¶ – The type id the resource to delete.
check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Deleting an User which id is foobar¶from scim2_models import User, SearchRequest response = scim.delete(User, "foobar") # 'response' may be None, or an Error object
- async replace(resource: AnyResource | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) AnyResource | Error | dict[source]¶
Perform a PUT request to replace a resource, as defined in RFC7644 §3.5.1.
- Parameters:
resource¶ – The new resource to replace. If is a
dict, the resource type will be guessed from the schema.check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
An
Errorobject in case of error.The updated object as returned by the server in case of success.
- Usage:
Replacement of a User resource¶from scim2_models import User user = scim.query(User, "my-used-id") user.display_name = "Fancy New Name" updated_user = scim.replace(user)
Tip
Check the
RESOURCE_REPLACEMENT_REQUESTandRESOURCE_REPLACEMENT_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- async modify(resource_model: type[ResourceT], id: str, patch_op: PatchOp[TypeVar] | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 204, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) ResourceT | Error | dict | None[source]¶
Perform a PATCH request to modify a resource, as defined in RFC7644 §3.5.2.
- Parameters:
resource_model¶ – The type of the resource to modify.
id¶ – The id of the resource to modify.
patch_op¶ – The
PatchOpobject describing the modifications. Must be parameterized with the same resource type asresource_model(e.g.,PatchOp[User]whenresource_modelisUser).check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Modification of a User resource¶from scim2_models import User, PatchOp, PatchOperation operation = PatchOperation( op="replace", path="displayName", value="New Display Name" ) patch_op = PatchOp[User](operations=[operation]) response = await scim.modify(User, "my-user-id", patch_op) # 'response' may be a User, None, or an Error object
Tip
Check the
RESOURCE_PATCH_REQUESTandRESOURCE_PATCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- class scim2_client.engines.werkzeug.TestSCIMClient(client: Client, environ: dict | None = None, scim_prefix: str = '', *args, **kwargs)[source]¶
A client based on
Werkzeug test Clientfor application development purposes.This is helpful for developers of SCIM servers. This client avoids to perform real HTTP requests and directly execute the server code instead. This allows to dynamically catch the exceptions if something gets wrong.
- Parameters:
client¶ – An optional custom
Werkzeug test Client. IfNonea default client is initialized.scim_prefix¶ – The scim root endpoint in the application.
environ¶ – Additional parameters that will be passed to every request.
resource_models¶ – A tuple of
Resourcetypes expected to be handled by the SCIM client. If a request payload describe a resource that is not in this list, an exception will be raised.check_request_payload¶ – If
False,resourceis expected to be a dict that will be passed as-is in the request. This value can be overwritten in methods.check_response_payload¶ – Whether to validate that the response payloads are valid. If set, the raw payload will be returned. This value can be overwritten in methods.
raise_scim_errors¶ – If
Trueand the server returned anErrorobject during a request, aSCIMResponseErrorObjectexception will be raised. IfFalsethe error object is returned. This value can be overwritten in methods.
from scim2_client.engines.werkzeug import TestSCIMClient from scim2_models import User, Group from werkzeug.test import Client scim_provider = myapp.create_app() testclient = TestSCIMClient( app=Client(scim_provider), environ={"base_url": "/scim/v2"}, resource_models=(User, Group), ) request_user = User(user_name="foo", display_name="bar") response_user = scim_client.create(request_user) assert response_user.user_name == "foo"
- create(resource: AnyResource | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs) AnyResource | Error | dict[source]¶
Perform a POST request to create, as defined in RFC7644 §3.3.
- Parameters:
resource¶ – The resource to create If is a
dict, the resource type will be guessed from the schema.check_request_payload¶ – If set, overwrites
check_request_payload.check_response_payload¶ – If set, overwrites
check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
Creation of a User resource¶from scim2_models import User request = User(user_name="bjensen@example.com") response = scim.create(request) # 'response' may be a User or an Error object
Tip
Check the
RESOURCE_CREATION_REQUESTandRESOURCE_CREATION_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- query(resource_model: type[Resource] | None = None, id: str | None = None, query_parameters: ResponseParameters | dict | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 400, 307, 308, 401, 403, 404, 500], raise_scim_errors: bool | None = None, search_request: ResponseParameters | dict | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]¶
Perform a GET request to read resources, as defined in RFC7644 §3.4.2.
If id is not
None, the resource with the exact id will be reached.If id is
None, all the resources with the given type will be reached.
- Parameters:
query_parameters¶ – A
ResponseParametersorSearchRequestdetailing the query parameters. UseResponseParameterswhen querying a single resource by id, where onlyattributesandexcludedAttributesare meaningful (RFC 7644 §3.4.1). UseSearchRequestwhen listing resources, to also passfilter,sortBy,sortOrder,startIndexandcount(RFC 7644 §3.4.2).check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
Note
Querying a
ServiceProviderConfigwill return a single object, and not aListResponse.- Usage:
Query of a User resource knowing its id¶from scim2_models import User response = scim.query(User, "my-user-id) # 'response' may be a User or an Error object
Query of all the User resources filtering the ones with userName starts with john¶from scim2_models import User, SearchRequest req = SearchRequest(filter='userName sw "john"') response = scim.query(User, query_parameters=req) # 'response' may be a ListResponse[User] or an Error object
Query of all the available resources¶from scim2_models import User response = scim.query() # 'response' may be a ListResponse[Union[User, Group, ...]] or an Error object
Tip
Check the
RESOURCE_QUERY_REQUESTandRESOURCE_QUERY_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- search(search_request: SearchRequest | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]¶
Perform a POST search request to read all available resources, as defined in RFC7644 §3.4.3.
- Parameters:
resource_models¶ – Resource type or union of types expected to be read from the response.
search_request¶ – An object detailing the search query parameters.
check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
A
Errorobject in case of error.A
ListResponse[resource_model]object in case of success.
- Usage:
Searching for all the resources filtering the ones with id contains with admin¶from scim2_models import User, SearchRequest req = SearchRequest(filter='id co "john"') response = scim.search(search_request=search_request) # 'response' may be a ListResponse[User] or an Error object
Tip
Check the
SEARCH_REQUESTandSEARCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- delete(resource_model: type[Resource], id: str, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [204, 307, 308, 400, 401, 403, 404, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Error | dict | None[source]¶
Perform a DELETE request to create, as defined in RFC7644 §3.6.
- Parameters:
resource_model¶ – The type of the resource to delete.
id¶ – The type id the resource to delete.
check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Deleting an User which id is foobar¶from scim2_models import User, SearchRequest response = scim.delete(User, "foobar") # 'response' may be None, or an Error object
- replace(resource: AnyResource | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) AnyResource | Error | dict[source]¶
Perform a PUT request to replace a resource, as defined in RFC7644 §3.5.1.
- Parameters:
resource¶ – The new resource to replace. If is a
dict, the resource type will be guessed from the schema.check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
An
Errorobject in case of error.The updated object as returned by the server in case of success.
- Usage:
Replacement of a User resource¶from scim2_models import User user = scim.query(User, "my-used-id") user.display_name = "Fancy New Name" updated_user = scim.replace(user)
Tip
Check the
RESOURCE_REPLACEMENT_REQUESTandRESOURCE_REPLACEMENT_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- modify(resource_model: type[ResourceT], id: str, patch_op: PatchOp[TypeVar] | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 204, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) ResourceT | Error | dict | None[source]¶
Perform a PATCH request to modify a resource, as defined in RFC7644 §3.5.2.
- Parameters:
resource_model¶ – The type of the resource to modify.
id¶ – The id of the resource to modify.
patch_op¶ – The
PatchOpobject describing the modifications. Must be parameterized with the same resource type asresource_model(e.g.,PatchOp[User]whenresource_modelisUser).check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Modification of a User resource¶from scim2_models import User, PatchOp, PatchOperation operation = PatchOperation( op="replace", path="displayName", value="New Display Name" ) patch_op = PatchOp[User](operations=[operation]) response = scim.modify(User, "my-user-id", patch_op) # 'response' may be a User, None, or an Error object
Tip
Check the
RESOURCE_PATCH_REQUESTandRESOURCE_PATCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- class scim2_client.SCIMClient(resource_models: Collection[type[Resource]] | None = None, resource_types: Collection[ResourceType] | None = None, service_provider_config: ServiceProviderConfig | None = None, check_request_payload: bool = True, check_response_payload: bool = True, check_response_content_type: bool = True, check_response_status_codes: bool = True, raise_scim_errors: bool = True)[source]¶
The base model for request clients.
It goal is to parse the requests and responses and check if they comply with the SCIM specifications.
This class can be inherited and used as a basis for request engine integration.
- Parameters:
resource_models¶ – A collection of
Resourcemodels expected to be handled by the SCIM client. If a request payload describe a resource that is not in this list, an exception will be raised.resource_types¶ – A collection of
ResourceTypethat will be used to guess the server endpoints associated with the resources.service_provider_config¶ – An instance of
ServiceProviderConfig.check_request_payload¶ – If
False,resourceis expected to be a dict that will be passed as-is in the request. This value can be overwritten in methods.check_response_payload¶ – Whether to validate that the response payloads are valid. If set, the raw payload will be returned. This value can be overwritten in methods.
check_response_content_type¶ – Whether to validate that the response content types are valid.
check_response_status_codes¶ – Whether to validate that the response status codes are valid.
raise_scim_errors¶ – If
Trueand the server returned anErrorobject during a request, aSCIMResponseErrorObjectexception will be raised. IfFalsethe error object is returned. This value can be overwritten in methods.
Note
ResourceType,Schemaandscim2_models.ServiceProviderConfigare pre-loaded by default.- CREATION_RESPONSE_STATUS_CODES: list[int] = [201, 409, 307, 308, 400, 401, 403, 404, 500]¶
Resource creation HTTP codes.
As defined at RFC7644 §3.3 and RFC7644 §3.12.
- QUERY_RESPONSE_STATUS_CODES: list[int] = [200, 400, 307, 308, 401, 403, 404, 500]¶
Resource querying HTTP codes.
As defined at RFC7644 §3.4.2 and RFC7644 §3.12.
- SEARCH_RESPONSE_STATUS_CODES: list[int] = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501]¶
Resource querying HTTP codes.
As defined at RFC7644 §3.4.3 and RFC7644 §3.12.
- DELETION_RESPONSE_STATUS_CODES: list[int] = [204, 307, 308, 400, 401, 403, 404, 412, 500, 501]¶
Resource deletion HTTP codes.
As defined at RFC7644 §3.6 and RFC7644 §3.12.
- REPLACEMENT_RESPONSE_STATUS_CODES: list[int] = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501]¶
Resource querying HTTP codes.
As defined at RFC7644 §3.4.2 and RFC7644 §3.12.
- PATCH_RESPONSE_STATUS_CODES: list[int] = [200, 204, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501]¶
Resource patching HTTP codes.
As defined at RFC7644 §3.5.2 and RFC7644 §3.12.
- get_resource_model(name: str) type[Resource] | None[source]¶
Get a registered model by its name or its schema.
- resource_endpoint(resource_model: type[Resource] | None) str[source]¶
Find the
endpointassociated with a givenResource.Internally, it looks if any
resource_typeof the client matches the resource_model by comparing schemas.
- register_naive_resource_types()[source]¶
Register a naive
ResourceTypefor eachresource_model.This fills the
ResourceTypewith generic values. The endpoint is the resource name with a s suffix. For instance, theUserwill have a /Users endpoint.
- build_resource_models(resource_types: Collection[ResourceType], schemas: Collection[Schema]) tuple[type[Resource]][source]¶
Build models from server objects.
- class scim2_client.BaseSyncSCIMClient(resource_models: Collection[type[Resource]] | None = None, resource_types: Collection[ResourceType] | None = None, service_provider_config: ServiceProviderConfig | None = None, check_request_payload: bool = True, check_response_payload: bool = True, check_response_content_type: bool = True, check_response_status_codes: bool = True, raise_scim_errors: bool = True)[source]¶
Base class for synchronous request clients.
- create(resource: AnyResource | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs) AnyResource | Error | dict[source]¶
Perform a POST request to create, as defined in RFC7644 §3.3.
- Parameters:
resource¶ – The resource to create If is a
dict, the resource type will be guessed from the schema.check_request_payload¶ – If set, overwrites
check_request_payload.check_response_payload¶ – If set, overwrites
check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
Creation of a User resource¶from scim2_models import User request = User(user_name="bjensen@example.com") response = scim.create(request) # 'response' may be a User or an Error object
Tip
Check the
RESOURCE_CREATION_REQUESTandRESOURCE_CREATION_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- query(resource_model: type[Resource] | None = None, id: str | None = None, query_parameters: ResponseParameters | dict | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 400, 307, 308, 401, 403, 404, 500], raise_scim_errors: bool | None = None, search_request: ResponseParameters | dict | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]¶
Perform a GET request to read resources, as defined in RFC7644 §3.4.2.
If id is not
None, the resource with the exact id will be reached.If id is
None, all the resources with the given type will be reached.
- Parameters:
query_parameters¶ – A
ResponseParametersorSearchRequestdetailing the query parameters. UseResponseParameterswhen querying a single resource by id, where onlyattributesandexcludedAttributesare meaningful (RFC 7644 §3.4.1). UseSearchRequestwhen listing resources, to also passfilter,sortBy,sortOrder,startIndexandcount(RFC 7644 §3.4.2).check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
Note
Querying a
ServiceProviderConfigwill return a single object, and not aListResponse.- Usage:
Query of a User resource knowing its id¶from scim2_models import User response = scim.query(User, "my-user-id) # 'response' may be a User or an Error object
Query of all the User resources filtering the ones with userName starts with john¶from scim2_models import User, SearchRequest req = SearchRequest(filter='userName sw "john"') response = scim.query(User, query_parameters=req) # 'response' may be a ListResponse[User] or an Error object
Query of all the available resources¶from scim2_models import User response = scim.query() # 'response' may be a ListResponse[Union[User, Group, ...]] or an Error object
Tip
Check the
RESOURCE_QUERY_REQUESTandRESOURCE_QUERY_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- search(search_request: SearchRequest | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]¶
Perform a POST search request to read all available resources, as defined in RFC7644 §3.4.3.
- Parameters:
resource_models¶ – Resource type or union of types expected to be read from the response.
search_request¶ – An object detailing the search query parameters.
check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
A
Errorobject in case of error.A
ListResponse[resource_model]object in case of success.
- Usage:
Searching for all the resources filtering the ones with id contains with admin¶from scim2_models import User, SearchRequest req = SearchRequest(filter='id co "john"') response = scim.search(search_request=search_request) # 'response' may be a ListResponse[User] or an Error object
Tip
Check the
SEARCH_REQUESTandSEARCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- delete(resource_model: type, id: str, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [204, 307, 308, 400, 401, 403, 404, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Error | dict | None[source]¶
Perform a DELETE request to create, as defined in RFC7644 §3.6.
- Parameters:
resource_model¶ – The type of the resource to delete.
id¶ – The type id the resource to delete.
check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Deleting an User which id is foobar¶from scim2_models import User, SearchRequest response = scim.delete(User, "foobar") # 'response' may be None, or an Error object
- replace(resource: AnyResource | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) AnyResource | Error | dict[source]¶
Perform a PUT request to replace a resource, as defined in RFC7644 §3.5.1.
- Parameters:
resource¶ – The new resource to replace. If is a
dict, the resource type will be guessed from the schema.check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
An
Errorobject in case of error.The updated object as returned by the server in case of success.
- Usage:
Replacement of a User resource¶from scim2_models import User user = scim.query(User, "my-used-id") user.display_name = "Fancy New Name" updated_user = scim.replace(user)
Tip
Check the
RESOURCE_REPLACEMENT_REQUESTandRESOURCE_REPLACEMENT_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- modify(resource_model: type[ResourceT], id: str, patch_op: PatchOp[TypeVar] | dict, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 204, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) ResourceT | Error | dict | None[source]¶
Perform a PATCH request to modify a resource, as defined in RFC7644 §3.5.2.
- Parameters:
resource_model¶ – The type of the resource to modify.
id¶ – The id of the resource to modify.
patch_op¶ – The
PatchOpobject describing the modifications. Must be parameterized with the same resource type asresource_model(e.g.,PatchOp[User]whenresource_modelisUser).check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Modification of a User resource¶from scim2_models import User, PatchOp, PatchOperation operation = PatchOperation( op="replace", path="displayName", value="New Display Name" ) patch_op = PatchOp[User](operations=[operation]) response = scim.modify(User, "my-user-id", patch_op) # 'response' may be a User, None, or an Error object
Tip
Check the
RESOURCE_PATCH_REQUESTandRESOURCE_PATCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- discover(schemas=True, resource_types=True, service_provider_config=True)[source]¶
Dynamically discover the server configuration objects.
- Parameters:
resource_types¶ – Whether to discover the
ResourceTypeendpoint.service_provider_config¶ – Whether to discover the
ServiceProviderConfigendpoint.
- exception scim2_client.SCIMClientError(message: str, source: Any = None, *args: Any, **kwargs: Any)[source]¶
Base exception for scim2-client.
- Parameters:
message – The exception reason.
source – The request payload or the response object that have caused the exception.
- exception scim2_client.SCIMRequestError(message: str, source: Any = None, *args: Any, **kwargs: Any)[source]¶
Base exception for errors happening during request payload building.
- exception scim2_client.SCIMResponseError(message: str, source: Any = None, *args: Any, **kwargs: Any)[source]¶
Base exception for errors happening during response payload validation.
- exception scim2_client.SCIMResponseErrorObject(error: Error, *args: Any, **kwargs: Any)[source]¶
The server response returned a
scim2_models.Errorobject.Those errors are only raised when the
raise_scim_errorsparameter isTrue.- Parameters:
error – The
Errorobject returned by the server.
- exception scim2_client.UnexpectedContentFormat(*args: Any, **kwargs: Any)[source]¶
Error raised when a server returned a response in a non-JSON format.
- exception scim2_client.UnexpectedContentType(content_type: str, *args: Any, **kwargs: Any)[source]¶
Error raised when a server returned an unexpected Content-Type header in a response.
- exception scim2_client.UnexpectedStatusCode(status_code: int, *args: Any, **kwargs: Any)[source]¶
Error raised when a server returned an unexpected status code for a given
Context.
- exception scim2_client.RequestPayloadValidationError(*args: Any, **kwargs: Any)[source]¶
Error raised when an invalid request payload has been passed to SCIMClient.
This error is raised when a
pydantic.ValidationErrorhas been caught while validating the client request payload. The originalValidationErroris available with__cause__.try: scim.create( { "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"], "active": "not-a-bool", } ) except RequestPayloadValidationError as exc: print("Original validation error cause", exc.__cause__)
- exception scim2_client.RequestNetworkError(*args: Any, **kwargs: Any)[source]¶
Error raised when a network error happened during request.
This error is raised when a
httpx.RequestErrorhas been caught while performing a request. The originalRequestErroris available with__cause__.
- exception scim2_client.ResponsePayloadValidationError(*args: Any, **kwargs: Any)[source]¶
Error raised when the server returned a payload that cannot be validated.
This error is raised when a
pydantic.ValidationErrorhas been caught while validating the server response payload. The originalValidationErroris available with__cause__.try: scim.query(User, "foobar") except ResponsePayloadValidationError as exc: print("Original validation error cause", exc.__cause__)