Describe the server#

Use this guide to tell a client which resources a server serves, under which endpoints, and what it is capable of. A ScimProvider holds the three, and the client reads it to pick the model a payload deserves and the URL a request goes to. See What a client knows about a server for what the client does with each part.

Let the server publish it#

discover() reads the ServiceProviderConfig, Schema and ResourceType endpoints RFC7644 §4 defines, and builds a model for every schema it finds:

scim.discover()
User = scim.get_resource_model("User")
EnterpriseUser = User.get_extension_model("EnterpriseUser")
await scim.discover()
User = scim.get_resource_model("User")
EnterpriseUser = User.get_extension_model("EnterpriseUser")

get_resource_model() returns the model a resource type is served under, and None for a name the server does not serve. The models discovery builds carry the attributes that server declares, extensions included, not the ones the specifications describe.

These models are built at runtime and do not inherit the scim2-models classes. A type checker sees scim.query(User, "123") as a User, since the request is made with User. At runtime, isinstance(user, User) is false. Check the class against the model get_resource_model() returns, or describe the server by hand to get instances of the scim2-models classes.

Each of the three endpoints can be left out, for a server that does not serve it:

scim.discover(service_provider_config=False)

Describe it by hand#

A server whose resources are known in advance needs no round trip. Pass a ScimProvider as the provider argument, listing the models and the ResourceType objects binding them to their endpoints:

from scim2_models import EnterpriseUser, Group, ResourceType, ScimProvider, User

scim = SyncSCIMClient(
    client,
    provider=ScimProvider(
        models=[User, EnterpriseUser, Group],
        resource_types=[
            ResourceType.from_resource(User[EnterpriseUser]),
            ResourceType.from_resource(Group),
        ],
    ),
)
from scim2_models import EnterpriseUser, Group, ResourceType, ScimProvider, User

scim = AsyncSCIMClient(
    client,
    provider=ScimProvider(
        models=[User, EnterpriseUser, Group],
        resource_types=[
            ResourceType.from_resource(User[EnterpriseUser]),
            ResourceType.from_resource(Group),
        ],
    ),
)

Resources carrying no extension and served at the regular endpoints — /Users for User, and so on — need no ResourceType at all, as the provider builds those itself:

from scim2_models import Group, ScimProvider, User

scim = SyncSCIMClient(client, provider=ScimProvider(models=[User, Group]))
from scim2_models import Group, ScimProvider, User

scim = AsyncSCIMClient(client, provider=ScimProvider(models=[User, Group]))

Describe what is known and discover the rest#

discover() only queries what the provider does not describe yet, so a client given part of the description keeps it and asks the server for the remainder. A server whose models are known but whose capabilities are not reads the latter alone:

scim = SyncSCIMClient(client, provider=ScimProvider(models=[User, Group]))

# Only the ServiceProviderConfig endpoint is queried
scim.discover()

A server publishing a description that does not hold together — a resource type naming a schema it does not publish, for instance — raises InvalidServiceDescriptionException, and the client keeps the description it had.