|
1 | 1 | # scim2-server |
2 | 2 |
|
3 | | -This is an example WSGI-SCIM server using [scim2-models](https://github.com/python-scim/scim2-models). |
4 | | -It utilizes [werkzeug](https://werkzeug.palletsprojects.com/) and keeps all resources in-memory, |
5 | | -they are lost once the process exits. |
| 3 | +A Python library that serves the SCIM protocol over any storage, built upon |
| 4 | +[scim2-models](https://scim2-models.readthedocs.io), following the |
| 5 | +[RFC7643](https://datatracker.ietf.org/doc/html/rfc7643.html) and |
| 6 | +[RFC7644](https://datatracker.ietf.org/doc/html/rfc7644.html) specifications. |
| 7 | +It validates the requests, applies them to the resources and builds the responses. |
| 8 | +The application only reads and writes the resources. |
| 9 | + |
| 10 | +It comes with an in-memory storage, WSGI and ASGI applications with no dependency, and a |
| 11 | +`scim2-server` command that serves a test server. |
| 12 | + |
| 13 | +## Who is it for? |
| 14 | + |
| 15 | +scim2-server is for projects that need to: |
| 16 | + |
| 17 | +- serve a standalone SCIM server; |
| 18 | +- add SCIM to an existing application, with SCIM models that describe its data; |
| 19 | +- test a SCIM client against a working server, from the `scim2-server` command, a container, or |
| 20 | + the [pytest-scim2-server](https://github.com/pytest-dev/pytest-scim2-server) fixture. |
| 21 | + |
| 22 | +## What's SCIM anyway? |
| 23 | + |
| 24 | +SCIM stands for System for Cross-domain Identity Management, and it is a provisioning protocol. |
| 25 | +Provisioning is the action of managing a set of resources across different services, usually users and groups. |
| 26 | +SCIM is often used between Identity Providers and applications in completion of standards like OAuth2 and OpenID Connect. |
| 27 | +It allows users and groups creations, modifications and deletions to be synchronized between applications. |
6 | 28 |
|
7 | 29 | ## Features |
8 | 30 |
|
9 | | -- [x] Discovery endpoints (`/v2/ServiceProviderConfig`, `/v2/ResourceTypes`, `/v2/Schemas`) |
10 | | -- [x] Create/Read/Update/Delete resources (`POST`, `GET`, `PUT`, `DELETE`) |
11 | | -- [x] Searching & Filtering |
12 | | -- [x] Support for ETags |
13 | | -- [x] Unique Constraints |
14 | | -- [x] HTTP PATCH (Add/Remove/Replace) |
15 | | -- [x] Sorting |
16 | | -- [x] Bulk operations |
17 | | -- [x] Multi-tenancy with a URL prefix |
| 31 | +- **Resources**: creation, read, replacement, PATCH and deletion |
| 32 | +- **Search**: filters, sorting, paging and attribute selection, on a resource type or at the root |
| 33 | +- **Bulk requests**: with `bulkId` references and `failOnErrors` |
| 34 | +- **ETags**: conditional requests and protection against concurrent writes |
| 35 | +- **Discovery**: `ServiceProviderConfig`, `ResourceTypes` and `Schemas` |
| 36 | +- **Storages**: an interface to implement, an in-memory storage, and a test suite that checks a storage |
| 37 | +- **Sync & Async**: a synchronous and an asynchronous handler, over the same rules |
| 38 | +- **Multi-tenancy**: one set of resources per URL prefix |
18 | 39 |
|
19 | | -## Usage |
| 40 | +## Installation |
20 | 41 |
|
21 | 42 | ```shell |
22 | | -$ scim2-server [-h] [--schema SCHEMA] [--resource-type RESOURCE_TYPE] [--service-provider-config SERVICE_PROVIDER_CONFIG] [--bearer-token BEARER_TOKEN] [--hostname HOSTNAME] [--port PORT] [--reverse-proxy] [--dump-resources DUMP_RESOURCES] [--tenant TENANT] [--dynamic-tenants] [--debug] |
| 43 | +pip install scim2-server |
23 | 44 | ``` |
24 | 45 |
|
25 | | -- `-h`/`--help`: Show help message |
26 | | -- `--reverse-proxy`: Allow using the provider behind a Reverse Proxy (required for URL rewriting). |
27 | | -- `--schema`: Register schemas from specified JSON file. If not provided, loads the default schemas from RFC 7643. |
28 | | -- `--resource-type`: Register resource types from specified JSON file. If not provided, loads the default resource types from RFC 7643. |
29 | | -- `--service-provider-config`: Load the service provider configuration from specified JSON file. If not provided, loads the default configuration. |
30 | | -- `--bearer-token`: Registers a bearer token that can be used for accessing the service, and announces the bearer token authentication scheme. If no tokens are provided, anonymous access without authentication is allowed. |
31 | | -- `--hostname`: The hostname to listen on. Defaults to `127.0.0.1`. |
32 | | -- `--port`: The port to listen on. Defaults to `8080`. |
33 | | -- `--dump-resources`: Dump a JSON document containing all resources when the provider exits normally. With tenants, the document has one entry per tenant. |
34 | | -- `--tenant`: Serve a tenant under `/<tenant>`, for example `/<tenant>/v2/Users`. Can be repeated. See [Multi-tenancy](#multi-tenancy). |
35 | | -- `--dynamic-tenants`: Create a tenant on the first request to `/<tenant>`. See [Multi-tenancy](#multi-tenancy). |
36 | | -- `--debug`: Enable the interactive Werkzeug debugger, the reloader and the logging of the WSGI environment of each request. The debugger allows arbitrary code execution and the environment contains the bearer tokens, so never use this option on a server reachable by others. |
37 | | - |
38 | | -### Multi-tenancy |
39 | | - |
40 | | -With `--tenant` or `--dynamic-tenants`, the first segment of the URL path selects a tenant (RFC 7644 §6.1). |
41 | | -Each tenant has its own resources: `/a/v2/Users` and `/b/v2/Users` are separate, and uniqueness, filters and pagination only consider the resources of the tenant. |
42 | | -The schemas, the resource types and the service provider configuration are the same for every tenant, and so are the bearer tokens. |
43 | | -A request without a known tenant gets a 404 answer, and `v2` cannot be a tenant name. |
| 46 | +## Usage |
| 47 | + |
| 48 | +Serve a test server from the command line: |
44 | 49 |
|
45 | 50 | ```shell |
46 | | -$ scim2-server --tenant a --tenant b |
47 | | -$ curl http://localhost:8080/a/v2/Users |
| 51 | +scim2-server --port 8080 |
48 | 52 | ``` |
49 | 53 |
|
50 | | -With `--dynamic-tenants`, the first request to an unknown tenant creates it with no resources. |
51 | | -This is useful for tests: each test can pick a random tenant and get an empty server. |
52 | | -Any client can then create tenants, even without a valid bearer token, and every tenant stays in memory until the server exits. |
53 | | -Do not use this option on a server reachable by untrusted clients. |
| 54 | +Or build the WSGI application in Python: |
54 | 55 |
|
55 | | -In Python, `scim2_server.tenants.TenantDispatcher` builds one `SCIMApplication` per tenant from a factory, on the first request to the tenant. |
56 | | -The factory gets the tenant name and returns `None` when the tenant does not exist. |
57 | | -Override its `select_tenant` method to read the tenant from a header or a sub-domain instead. |
| 56 | +```python |
| 57 | +from scim2_server.applications.wsgi import WSGIApplication |
| 58 | +from scim2_server.memory import InMemoryStorage |
| 59 | +from scim2_server.utils import load_default_provider |
58 | 60 |
|
59 | | -### Container |
| 61 | +app = WSGIApplication(InMemoryStorage(), load_default_provider()) |
| 62 | +``` |
60 | 63 |
|
61 | | -A container image is published on the GitHub container registry for each release. |
62 | | -The server listens on `0.0.0.0:8080` inside the container, and the command line arguments are passed to `scim2-server`: |
| 64 | +A container image is published on the GitHub container registry for each release: |
63 | 65 |
|
64 | 66 | ```shell |
65 | | -$ docker run --publish 8080:8080 ghcr.io/python-scim/scim2-server --bearer-token secret |
| 67 | +docker run --publish 8080:8080 ghcr.io/python-scim/scim2-server --bearer-token secret |
66 | 68 | ``` |
67 | 69 |
|
68 | | -To build the image yourself, use `docker build --file Containerfile .` or `podman build .`. |
| 70 | +The server has been tested against a live |
| 71 | +[Microsoft Entra](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/scim-validator-tutorial) |
| 72 | +system and a live |
| 73 | +[Okta](https://developer.okta.com/docs/guides/scim-provisioning-integration-test/main/) system. |
69 | 74 |
|
70 | | -## Notes |
| 75 | +## Documentation |
71 | 76 |
|
72 | | -This provider can be used as a starting point if you want to implement a SCIM provider. You should probably change the following things, if you want to use it in production: |
| 77 | +- [Overview](https://scim2-server.readthedocs.io/en/latest/overview.html) introduces the parts of |
| 78 | + a SCIM server, from the description of the service to the test server. |
| 79 | +- [How-to guides](https://scim2-server.readthedocs.io/en/latest/how-to/index.html) cover focused |
| 80 | + tasks, such as writing a storage or integrating a web framework. |
| 81 | +- [Explanation](https://scim2-server.readthedocs.io/en/latest/explanation/index.html) covers the |
| 82 | + layers of the server, the writes of resources and the bulk requests. |
| 83 | +- [Reference](https://scim2-server.readthedocs.io/en/latest/reference.html) lists the public API |
| 84 | + and the options of the `scim2-server` command. |
73 | 85 |
|
74 | | -- Use a proper production WSGI server instead of the one provided by Werkzeug |
75 | | -- Implement your own storage as a subclass of `scim2_server.storage.ScimStorage`, and check it with `scim2_server.testing.ScimStorageContract` |
76 | | -- Implement proper authorization with OAuth instead of public access or static bearer tokens |
77 | | -- Support the `/Me` endpoint, if it applies in your use case |
| 86 | +## Contributing |
78 | 87 |
|
79 | | -The provider in its current state has been tested successfully against a live |
80 | | -[Microsoft Entra](https://learn.microsoft.com/en-us/entra/identity/app-provisioning/scim-validator-tutorial) |
81 | | -system as well as a live |
82 | | -[Okta](https://developer.okta.com/docs/guides/scim-provisioning-integration-test/main/) system. |
| 88 | +The [contribution page](https://scim2-server.readthedocs.io/en/latest/contributing.html) |
| 89 | +describes how to run the tests, the style checks and the documentation build. |
| 90 | + |
| 91 | +scim2-server belongs in a collection of SCIM tools developed by [Yaal Coop](https://yaal.coop), |
| 92 | +with [scim2-models](https://github.com/python-scim/scim2-models), |
| 93 | +[scim2-client](https://github.com/python-scim/scim2-client), |
| 94 | +[scim2-tester](https://github.com/python-scim/scim2-tester) and |
| 95 | +[scim2-cli](https://github.com/python-scim/scim2-cli). |
83 | 96 |
|
84 | 97 | ## Origins |
85 | 98 |
|
|
0 commit comments