SCIM2 Server Prototype
scim2-server is a lightweight prototype implementation of a SCIM2 (System for Cross-domain Identity Management) server using FastAPI. It provides basic in-memory reference implementations for SCIM2 user and group management, primarily intended as a starting point or demonstration rather than a production-ready server. The current version is 0.1.9, with an irregular release cadence as a 'prototype'.
Common errors
-
ModuleNotFoundError: No module named 'scim2-server'
cause Attempted to import using the package name (`scim2-server` with a hyphen) instead of the correct module name (`scim2_server` with an underscore).fixChange your import statement from `from scim2-server import ...` to `from scim2_server import ...`. -
uvicorn.run(): No application object specified. Ensure your run command points to your FastAPI app.
cause Uvicorn was either not installed, or the command to start the server was incorrect, preventing it from finding the FastAPI application instance.fixFirst, ensure `uvicorn` is installed (`pip install uvicorn`). Then, make sure your startup command correctly points to your FastAPI app, e.g., if your app is named `app` in `main.py`, run `uvicorn main:app --reload`. -
PydanticValidationError: 1 validation error for SCIM2User userName field required (type=value_error.missing)
cause When creating `SCIM2User` or `SCIM2Group` objects, a required field (like `userName` for users or `displayName` for groups) was omitted or provided with an invalid type.fixRefer to the SCIM2 specification and the library's Pydantic models (e.g., `SCIM2User` definition) to ensure all required attributes are provided with valid data types upon instantiation.
Warnings
- gotcha This library is explicitly a 'prototype' and 'in-memory reference implementation'. It is not designed for production use without significant modification for persistence, scalability, and security.
- gotcha The package name for installation is `scim2-server` (with a hyphen), but the Python module name for imports is `scim2_server` (with an underscore).
- gotcha Running the SCIM2 server requires FastAPI and an ASGI server like Uvicorn. While FastAPI is a direct dependency, Uvicorn (though listed) requires explicit installation and knowledge of how to start a FastAPI app.
Install
-
pip install scim2-server -
pip install uvicorn
Imports
- SCIM2Server
from scim2-server import SCIM2Server
from scim2_server import SCIM2Server
- SCIM2User
from scim2server.models import SCIM2User
from scim2_server import SCIM2User
- SCIM2Group
from scim2_server import SCIM2Group
Quickstart
import uvicorn
from fastapi import FastAPI
from scim2_server import SCIM2Server, SCIM2User, SCIM2Group
# Initialize SCIM2 server with in-memory storage
scim_server = SCIM2Server()
# Optional: Add some initial data
scim_server.users.create(SCIM2User(id='user1', userName='john.doe', emails=[{'value': 'john.doe@example.com', 'primary': True}]))
scim_server.groups.create(SCIM2Group(id='group1', displayName='Developers'))
# Create a FastAPI app and include the SCIM2 router
app = FastAPI(title="SCIM2 Prototype API")
app.include_router(scim_server.router, prefix="/scim/v2")
@app.get("/")
async def root():
return {"message": "SCIM2 server is running! Access /scim/v2"}
# To run this: save as main.py and execute 'uvicorn main:app --reload'
# The example below demonstrates running programmatically for convenience,
# but 'uvicorn main:app' is the typical way.
if __name__ == '__main__':
# Note: For production, typically run with `uvicorn main:app` from terminal.
# This programmatic run is for quick demonstration.
print("\n--- Running SCIM2 Server Prototype ---")
print("Access SCIM endpoints at: http://127.0.0.1:8000/scim/v2")
print("Try: http://127.0.0.1:8000/scim/v2/Users")
uvicorn.run(app, host="127.0.0.1", port=8000)