Reference#

This reference describes the public scim2-flask API. The scim2-server reference describes the storage contract, the service and the other classes the extension relies on.

Extension#

The Flask extension serving the SCIM endpoints.

class scim2_flask.ScimServer(storage: ScimStorage, provider: ScimProvider, app: Flask | None = None, *, service: ScimService | None = None, url_prefix: str = '/scim/v2', name: str = 'scim')[source]#

Flask extension exposing a SCIM 2.0 server backed by a ScimStorage.

The ScimProvider describes the service: the resource types it serves, the configuration it announces, and the policy the extension applies when it reads and writes payloads.

Usage:

storage = MyStorage()
scim_server = ScimServer(storage, ScimProvider(models=[User]))
scim_server.init_app(app)

Or with the application factory pattern:

scim_server = ScimServer(storage, ScimProvider(models=[User]))


def create_app():
    app = Flask(__name__)
    scim_server.init_app(app)
    return app
Parameters:
  • storage – The storage that holds the resources.

  • provider – The service description. It must declare at least one resource type.

  • app – The application to register on right away, if any.

  • service – The service serving the requests. By default, init_app() builds one upon provider, with the secret_key of the application as the secret of the cursors. Pass a subclass of ScimService to change one of its steps, such as the URL of the resources.

  • url_prefix – The URL prefix of the SCIM endpoints.

  • name – The name of the blueprint, and so the prefix of its endpoints. Give each instance its own name to serve several SCIM servers from one application.

create_blueprint() → Blueprint[source]#

Return the Blueprint serving the SCIM endpoints.

It has one endpoint per route of ROUTES, named after the route, such as scim.query, whose arguments are resource_endpoint and resource_id. A fallback endpoint answers the other requests with a SCIM error.

get_subject() → Any[source]#

Return the authenticated subject of the current request.

It returns None by default. Override it to pass the subject your application authenticated to the service, for authorize() and /Me.

init_app(app: Flask) → None[source]#

Register the SCIM blueprint on app, under url_prefix.

The extension is then available in the "scim" entry of extensions, under its name. Load the configuration of the application first: the default service reads its SECRET_KEY here.

Raises:

ValueError – When the configuration of the service announces cursor pagination, and the application has no SECRET_KEY.

read_body(scim_request: ScimRequest) → bytes[source]#

Read the body of the current request, up to one byte more than the service accepts.

The service answers a larger body with a 413. The MAX_CONTENT_LENGTH of the application still applies.

read_request() → ScimRequest[source]#

Return the ScimRequest of the current Flask request.